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
 

Some videos you may like

Excel Facts

Difference between two dates
Secret function! Use =DATEDIF(A2,B2,"Y")&" years"&=DATEDIF(A2,B2,"YM")&" months"&=DATEDIF(A2,B2,"MD")&" days"

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
 

Watch MrExcel Video

Forum statistics

Threads
1,122,224
Messages
5,594,914
Members
413,952
Latest member
JGer

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