Macro - how to change a cell reference in a loop.

andy-s

Board Regular
Joined
Mar 22, 2002
Messages
51
Could anyone please help me with the macro below - look for "THIS IS MY PROBLEM"


Code:
Sub Transfer()

Dim LRD As Long     'last row datasheet

Set DS = Sheets("Rawdata")

LRD = DS.Range("C8:C" & Rows.Count).Find("*", DS.[C8], xlFormulas, xlPart, xlByRows, xlPrevious, False, False).Row

For Counter = 9 To LRD

    'THIS IS MY PROBLEM – Every time Counter change, the cell reference R[9]C[24] should change as well. When Counter change to 10, the cell reference should change to R[10]C[24] and so on. How do I do this?
    Sheets("Processing").Select
    Range("A1").Select
    Application.CutCopyMode = False
    ActiveCell.FormulaR1C1 = "='Rawdata'!R[9]C[24]"
  
    'Copy data from Processing to Rawdata
    With Sheets("Rawdata")
    NxRow = .Cells(65536, 28).End(xlUp).Row + 1
    .Cells(NxRow, 28).Value = Sheets("Processing").Range("A29:A29").Value
    End With
    
Next Counter

End Sub
 

Excel Facts

VLOOKUP to Left?
Use =VLOOKUP(A2,CHOOSE({1,2},$Z$1:$Z$99,$Y$1:$Y$99),2,False) to lookup Y values to left of Z values.

RalphA

Well-known Member
Joined
May 14, 2003
Messages
3,829
Try changing your line,
ActiveCell.FormulaR1C1 = "='Rawdata'!R[9]C[24]"
to
ActiveCell.FormulaR1C1 = "='Rawdata'!R[Counter]C[24]"
 

erik.van.geit

MrExcel MVP
Joined
Feb 1, 2003
Messages
17,832
Hello, andy-s,

try this
ActiveCell.FormulaR1C1 = "='Rawdata'!R[" & Counter & "]C[24]"

kind regards,
Erik
 
Master Excel Bundle

Excel contains over 450 functions, with more added every year. That’s a huge number, so where should you start? Right here with this bundle.

Forum statistics

Threads
1,163,982
Messages
5,834,688
Members
430,310
Latest member
Excelorate3305

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
Top