Note that there are some explanatory texts on larger screens.

plurals
  1. POExcel VBA [Complex .formulaR1C1 not working]
    primarykey
    data
    text
    <p>Here is my line of code:</p> <p><code>ActiveCell.FormulaR1C1 = "='Main'!R[9]C[0]&amp;LEFT("" "",5-LEN('Main'!R[9]C[1])) &amp;'Main'!R[9]C[1]&amp;"" ""&amp;DAY('Main'!R[4]C[8]) &amp; ""-"" &amp; UPPER(TEXT('Main'!R[4]C[8],""mmm"")) &amp; ""-"" &amp;YEAR('Main'R[4]C[8])&amp;"" "" &amp; 'Main'!R[9]C[3] &amp; "" "" &amp; 'Main'!R[9]C[4] &amp; "" "" &amp; LEFT('Main'!R[9]C[5],35)&amp; LEFT("" "",35-LEN(LEFT('Main'!R[9]C[5],35))) &amp; "" "" &amp; LEFT("" "", 12-LEN('Main'!R[9]C[6]))&amp; 'Main'!R[9]C[6] &amp; "" "" &amp; 'Main'!R[9]C[7] &amp; "" "" &amp; LEFT('Main'!R[4]C[9],9) &amp; LEFT("" "",9-LEN(LEFT('Main'!R[4]C[9],9))) &amp; "" "" &amp; 'Main'!R[9]C[2] &amp; LEFT("" "",4-LEN('Main'!R[9]C[2])) &amp; "" DATALOAD"""</code></p> <p>I'm getting a <code>run-time error 1004</code> saying its an <code>application-defined or object-defined error</code>. The problem is I'm not super familiar with VBA. There is quite a bit of stuff going on in this formula. Essentially all I need is to paste data onto a new sheet in an EXACT format. That's why there are a bunch of spaces and such. I use <code>R1C1</code> because each row has different data on sheet 1 and needs to be pasted into sheet 2 accordingly. </p> <p>Any ideas on why this code is running into an error? Any help would be greatly appreciated.</p> <p>For clarification: My whole macro is as follows...</p> <pre><code>Dim row As Integer Dim col As String col = "A" row = 1 Do Until IsEmpty(ActiveCell) Sheets("Protected").Select Range(col &amp; row).Select ActiveCell.FormulaR1C1 = "big long code as mentioned above goes here" Sheets("Main").Select ActiveCell.Offset(1, 0).Select row = row + 1 </code></pre> <p><strong>Copied From Comments</strong></p> <p>The actual working formula is</p> <p><code>=Main!A11&amp;LEFT(" ",5-LEN(Main!B11)) &amp;Main!B11&amp;" "&amp;DAY(Main!$D$6) &amp; "-" &amp; UPPER(TEXT(Main!$D$6,"mmm")) &amp; "-" &amp;YEAR(Main!$D$6)&amp;" " &amp; Main!D11 &amp; " " &amp; Main!E11 &amp; " " &amp; LEFT(Main!F11,35)&amp; LEFT(" ",35-LEN(LEFT(Main!F11,35))) &amp; " " &amp; LEFT(" ", 12-LEN(Main!G11))&amp; Main!G11 &amp; " " &amp; Main!H11 &amp; " " &amp; LEFT(Main!$E$6,9) &amp; LEFT(" ",9-LEN(LEFT(Main!$E$6,9))) &amp; " " &amp; Main!C11 &amp; LEFT(" ",4-LEN(Main!C11)) &amp; " DATALOAD"</code></p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload