VBA Formula in Loop Where Main Reference is Variable

chimneytop

New Member
Joined
Aug 13, 2015
Messages
7
Hey everyone,

I'm working on making a macro that will organize data for a mail merge. The main table is contains 62 lines of data for each person, with the first cell containing multiple rows. I'm using substitute to get around this.

If we aren't in VBA, the formula would be 'Output'!A3 = Substitute('Import'!A63,Char(10),":"), 'Output'!A4 = Substitute('Import'A126,Char(10),":"), ...

There is more code than what I've written below, but the yellow code is where my debugger gets unhappy. How do I make it pull the correct cell?

' Declaring Variables I
Dim i As Integer
Dim i_import_count_request As Integer
i_import_count = InputBox("How many records did you import?")
Dim s_plan_admin As String
s_plan_admin = InputBox("Who is the plan administrator / ER?")
Dim i_start_record As Integer

' Declaring Variables II
Dim ws_imported As Worksheet
Set ws_imported = Sheets("Imported")
Dim ws_output As Worksheet
Set ws_output = Sheets("Output")


' Nth record
ws_output.Select
Range("A1").Select
For i = 1 To i_import_count
i_start_record = 63 * (i - 1)
Range("A1").Offset(i, 0).Select
ActiveCell.FormulaR1C1 = "=SUBSTITUTE(Imported!R[i_start_record]C,CHAR(10),"":"")"


Next i
 

Excel Facts

Using Function Arguments with nested formulas
If writing INDEX in Func. Arguments, type MATCH(. Use the mouse to click inside MATCH in the formula bar. Dialog switches to MATCH.
Solved my own problem

ActiveCell.FormulaR1C1 = "=SUBSTITUTE(Imported!R[" & i_start_record & "]C,CHAR(10),"":"")"
 
Upvote 0
How about
Code:
ActiveCell.FormulaR1C1 = "=SUBSTITUTE(Imported!R" & i_start_record & "C,CHAR(10),"":"")"
 
Upvote 0

Forum statistics

Threads
1,214,528
Messages
6,120,065
Members
448,941
Latest member
AlphaRino

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top