VBA 런타임 오류 '1004': 응용 프로그램 정의 또는 개체 정의 오류" 설정 셀 내용 (VBA Runtime Error '1004': Application-defined or Object-defined error" setting cell contents)


문제 설명

VBA 런타임 오류 '1004': 응용 프로그램 정의 또는 개체 정의 오류" 설정 셀 내용 (VBA Runtime Error '1004': Application‑defined or Object‑defined error" setting cell contents)

셀 내용을 설정할 때, 특히 줄의 셀 내용을 설정할 때 오류 1004가 발생합니다.

6
 ActiveCell.FormulaR1C1 = "=""Total increase in GBP ""&MENU!R11C10"""

동일한 코드가 여러 시트에서 사용되며 일부 작업에서는 이 오류가 발생합니다. 기본적으로 "21BG"로 시작하는 참조 코드가 있는 행의 총계를 추가한 다음 설명을 인쇄하려고 합니다.

"총 GBP £TOTAL 증가"

또는

"총 GBP £TOTAL 감소" 합계에 따라 다릅니다.

매크로는 다음과 같습니다.

Sub AdjustGBP()
'
' Macro4 Macro


    Range("B65536").Select
    Selection.End(xlUp).Select
    ActiveCell.Offset(1, 0).Select
    ActiveCell.FormulaR1C1 = "21BG"

    ActiveCell.Offset(‑1, 1).Select
    Selection.Copy
    ActiveCell.Offset(1, 0).Select
    Selection.PasteSpecial Paste:=xlPasteValues

    ActiveCell.Offset(0, 1).Select
    ActiveCell.FormulaR1C1 = "11041202"

    ActiveCell.Offset(0, 1).Select
    ActiveCell.FormulaR1C1 = "Current deposits GBP"

    ActiveCell.Offset(0, 1).Select
    ActiveCell.FormulaR1C1 = "当座預金 GBP"

    ActiveCell.Offset(0, 5).Select
    Selection.Copy
    If ActiveCell.Value > 0 Then

    ActiveCell.Offset(0, ‑2).Select
    Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlSubtract

    ActiveCell.Offset(0, ‑2).Select
'    ActiveCell.FormulaR1C1 = "Total increase in GBP XXX 2007"
    ActiveCell.FormulaR1C1 = "=""Total increase in GBP ""&MENU!R11C10"""

    Else

    ActiveCell.Offset(0, ‑1).Select
    Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlSubtract

    ActiveCell.Offset(0, ‑3).Select
'    ActiveCell.FormulaR1C1 = "=""Total Decrease in " & "MENU!R11C10""
    ActiveCell.FormulaR1C1 = "=""Total Decrease in GBP ""&MENU!R11C10&"" 2021"""

End If

    ActiveCell.Select
    Selection.Copy
    Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
        :=False, Transpose:=False

    Range(ActiveCell.Offset(‑3, ‑5), ActiveCell.Offset(0, 4)).Select
    With Selection.Borders(xlEdgeBottom)
        .Weight = xlMedium
    End With
    With Selection.Borders(xlInsideHorizontal)
        .Weight = xlThin
    End With

End Sub

참조 솔루션

방법 1:

Don't forget to join strings using "&" operator.

ActiveCell.FormulaR1C1 = "=" & Chr(34) & "Total increase in GBP " & Chr(34) & "&MENU!R11C10"

방법 2:

This line

ActiveCell.FormulaR1C1 = "=""Total increase in GBP ""&MENU!R11C10"""

would look as formula like

="Total increase in GBP "&MENU!R11C10"

so it has one " in the end that should not be there!

The line should look like

ActiveCell.FormulaR1C1 = "=""Total increase in GBP ""&MENU!R11C10"

to get this formula

="Total increase in GBP "&MENU!R11C10

(by JamesKoheletPᴇʜ)

참조 문서

  1. VBA Runtime Error '1004': Application‑defined or Object‑defined error" setting cell contents (CC BY‑SA 2.5/3.0/4.0)

#vba #runtime-error #excel






관련 질문

열에 문자열이 포함된 경우 열 번호 나열 (List column numbers if columns contain string)

SpinButton SpinUp 또는 SpinDown 새로 고침 (Refreshing SpinButton SpinUp or SpinDown)

변수를 사용하여 Excel VBA에서 3차원 배열 요소에 액세스 (Use variables to access 3 dimensional array elements in Excel VBA)

TODAY() 함수와 월 1일을 기준으로 범위 이동 (Moving a range based on TODAY() function and first of the month)

ALV 레이아웃의 표시된 모든 열을 제거하는 방법 (How to remove all displayed columns of ALV layout)

셀에 입력한 msoShapeOval은 MsoShapeType으로 선언된 변수의 값이 될 수 없습니다. (msoShapeOval entered in cell not allowed to be value for variable declared as MsoShapeType)

Excel VBA의 세로 열에 여러 json을 생성하는 방법은 무엇입니까? (How to generate multiple json in vertical column in Excel VBA?)

공개 함수의 VBA 런타임 오류 -2147319767(80028029) (VBA Run-time error -2147319767 (80028029) in Public Function)

알 수 없는 수의 문자를 패턴 일치시키는 방법 (How to Pattern Match an Unknown Number of Characters)

Excel VBA 파일이 열려 있는지 확인 기능 (Excel VBA Check if File is open function)

ActiveCell..Offset(-1,0)=을 사용하는 If/And/Then/Else 문의 VBA 문제= (VBA Issue with If/And/Then/Else statement using ActiveCell..Offset(-1,0)=)

VBA 런타임 오류 '1004': 응용 프로그램 정의 또는 개체 정의 오류" 설정 셀 내용 (VBA Runtime Error '1004': Application-defined or Object-defined error" setting cell contents)







코멘트