I have this code below. How can I set a cell value to = whats looping through that value?
Sub Test2()
' Select cell A2, *first line of data*.
Range("A2").Select
' Set Do loop to stop when an empty cell is reached.
Do Until IsEmpty(ActiveCell)
' Insert your code here.
' Step down 1 row from present location.
ActiveCell.Offset(1, 0).Select
Loop
End Sub
My answer will better look like a comment but it is too long to fit in a comment (and cannot be formatted properly).
How to loop over a range
I advise you to have a look at Chip Pearson page about optimizing VBA, especially looping over range in VBA.
When you loop over range, you shoul use the
for eachstatement as described in this example:Finding the last empty cell
Your code seems to try to find the last empty cell. You can do it easily with
You can find some more tips on ozgrid (even if they don’t use
rows.count)Avoiding Selects
Your code will be very very slow if you are trying to
Selectevery cell in a loop.You’d better use the object model of VBA.
For instance, if you only want to copy the value of a cell:
Don’t do
Do