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

Round to nearest half hour?
Use =MROUND(A2,"0:30") to round to nearest half hour. Use =CEILING(A2,"0:30") to round to next half hour.
Try changing your line,
ActiveCell.FormulaR1C1 = "='Rawdata'!R[9]C[24]"
to
ActiveCell.FormulaR1C1 = "='Rawdata'!R[Counter]C[24]"
 
Upvote 0
Hello, andy-s,

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

kind regards,
Erik
 
Upvote 0

Forum statistics

Threads
1,214,606
Messages
6,120,483
Members
448,967
Latest member
visheshkotha

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