这是我的代码行:
ActiveCell.FormulaR1C1 = "='Main'!R[9]C[0]&LEFT("" "",5-LEN('Main'!R[9]C[1])) &'Main'!R[9]C[1]&"" ""&DAY('Main'!R[4]C[8]) & ""-"" & UPPER(TEXT('Main'!R[4]C[8],""mmm"")) & ""-"" &YEAR('Main'R[4]C[8])&"" "" & 'Main'!R[9]C[3] & "" "" & 'Main'!R[9]C[4] & "" "" & LEFT('Main'!R[9]C[5],35)& LEFT("" "",35-LEN(LEFT('Main'!R[9]C[5],35))) & "" "" & LEFT("" "", 12-LEN('Main'!R[9]C[6]))& 'Main'!R[9]C[6] & "" "" & 'Main'!R[9]C[7] & "" "" & LEFT('Main'!R[4]C[9],9) & LEFT("" "",9-LEN(LEFT('Main'!R[4]C[9],9))) & "" "" & 'Main'!R[9]C[2] & LEFT("" "",4-LEN('Main'!R[9]C[2])) & "" DATALOAD"""
我得到一个run-time error 1004
说法,它是一个application-defined or object-defined error
。问题是我对 VBA 不是很熟悉。这个公式中有很多东西。基本上,我需要的只是将数据以 EXACT 格式粘贴到新工作表上。这就是为什么会有一堆空格之类的。我之所以使用R1C1
,是因为每行在工作表 1 上都有不同的数据,需要相应地粘贴到工作表 2 中。
关于为什么此代码遇到错误的任何想法?任何帮助将不胜感激。
为了澄清:我的整个宏如下......
Dim row As Integer
Dim col As String
col = "A"
row = 1
Do Until IsEmpty(ActiveCell)
Sheets("Protected").Select
Range(col & row).Select
ActiveCell.FormulaR1C1 = "big long code as mentioned above goes here"
Sheets("Main").Select
ActiveCell.Offset(1, 0).Select
row = row + 1
从评论中复制
实际工作公式为
=Main!A11&LEFT(" ",5-LEN(Main!B11)) &Main!B11&" "&DAY(Main!$D$6) & "-" & UPPER(TEXT(Main!$D$6,"mmm")) & "-" &YEAR(Main!$D$6)&" " & Main!D11 & " " & Main!E11 & " " & LEFT(Main!F11,35)& LEFT(" ",35-LEN(LEFT(Main!F11,35))) & " " & LEFT(" ", 12-LEN(Main!G11))& Main!G11 & " " & Main!H11 & " " & LEFT(Main!$E$6,9) & LEFT(" ",9-LEN(LEFT(Main!$E$6,9))) & " " & Main!C11 & LEFT(" ",4-LEN(Main!C11)) & " DATALOAD"