Hi,
This is probably very easy, but being very new to VBA I've gotten myself a little stuck. I record macro's then try to edit them in order to make them a little bit more dynamic and try to take out any unnessessary code.
I have browsed this forum and found how to Copy a formula down to the last row of data, like this:
Range("AT1").Select
ActiveCell.FormulaR1C1 = "RESCF"
Dim lRow As Long
lRow = Cells.Find("*", searchorder:=xlByRows, searchdirection:=xlPrevious).Row
With Range("AT2")
.FormulaR1C1 = _
"=RC[-35]"
.AutoFill Destination:=Range("AT2:AT" & lRow)
End With
I then want to do pretty much the same again, but using another formula based on a different cell. Like this:
Range("AU1").Select
ActiveCell.FormulaR1C1 = "RESNEW"
Dim lRow As Long
lRow = Cells.Find("*", searchorder:=xlByRows, searchdirection:=xlPrevious).Row
With Range("AU2")
.FormulaR1C1 = _
"=IF(RC[-6]=""Block Subsidy"",""SPOT"",""BLOCK"")"
.AutoFill Destination:=Range("AU2:AU" & lRow)
End With
When i try to run this I get the following error:
"Compile Error
Duplicate declaration in current scope"
and VB highlights "lRow As Long", now i assume this is because i cannot use this declaration more than once. Why is this and how can i get round it?
Thanks in advance for your help
This is probably very easy, but being very new to VBA I've gotten myself a little stuck. I record macro's then try to edit them in order to make them a little bit more dynamic and try to take out any unnessessary code.
I have browsed this forum and found how to Copy a formula down to the last row of data, like this:
Range("AT1").Select
ActiveCell.FormulaR1C1 = "RESCF"
Dim lRow As Long
lRow = Cells.Find("*", searchorder:=xlByRows, searchdirection:=xlPrevious).Row
With Range("AT2")
.FormulaR1C1 = _
"=RC[-35]"
.AutoFill Destination:=Range("AT2:AT" & lRow)
End With
I then want to do pretty much the same again, but using another formula based on a different cell. Like this:
Range("AU1").Select
ActiveCell.FormulaR1C1 = "RESNEW"
Dim lRow As Long
lRow = Cells.Find("*", searchorder:=xlByRows, searchdirection:=xlPrevious).Row
With Range("AU2")
.FormulaR1C1 = _
"=IF(RC[-6]=""Block Subsidy"",""SPOT"",""BLOCK"")"
.AutoFill Destination:=Range("AU2:AU" & lRow)
End With
When i try to run this I get the following error:
"Compile Error
Duplicate declaration in current scope"
and VB highlights "lRow As Long", now i assume this is because i cannot use this declaration more than once. Why is this and how can i get round it?
Thanks in advance for your help