Hello. I am having problems with a small loop I wrote. The loop is designed to look at a worksheet and loop through it until it reaches the last row. It is supposed to take the row number and add it to the formula and insert it into another cell. The code I am using is
**************************************************
Sub PrintAll()
Dim lnLast As Long
lnLast = Range("A4").End(xlDown).Row
For x = 3 To lnLast
Range("B2").Select
ActiveCell.FormulaR1C1 = "=Data!A" & (x)
ActiveWindow.SelectedSheets.PrintOut Copies:=1, Collate:=True
Next x
Range("B2").Select
ActiveCell.FormulaR1C1 = "=Data!A" & (lnLast)
End Sub
**************************************************
Each time it hits the piece of code: "=Data!A" & (x) it displays the correct data in the VB editor watch window. The correct value for the first time in the loop would be =Data!A3, but instead it puts =Data!'A3' into the selected cells value. The quotation mark in the formula is screwing it up but I can't figure out how to pass the value without the quotation mark. Any ideas? Thanks.
**************************************************
Sub PrintAll()
Dim lnLast As Long
lnLast = Range("A4").End(xlDown).Row
For x = 3 To lnLast
Range("B2").Select
ActiveCell.FormulaR1C1 = "=Data!A" & (x)
ActiveWindow.SelectedSheets.PrintOut Copies:=1, Collate:=True
Next x
Range("B2").Select
ActiveCell.FormulaR1C1 = "=Data!A" & (lnLast)
End Sub
**************************************************
Each time it hits the piece of code: "=Data!A" & (x) it displays the correct data in the VB editor watch window. The correct value for the first time in the loop would be =Data!A3, but instead it puts =Data!'A3' into the selected cells value. The quotation mark in the formula is screwing it up but I can't figure out how to pass the value without the quotation mark. Any ideas? Thanks.