A Conversation for The H2G2 Programmers' Corner

Excel Macro Help

Post 1

Lakeman

This must be very easy but I can't for the life of me find out how to do it. In a visual basic macro all I want to do is move the active cell down. (It's just part of a loop that goes down a column looking for something.)


Excel Macro Help

Post 2

Santragenius V

One quick and dirty way (assuming that you know the range you're manouvering within):

Sub AddressRows()
Dim i As Integer

For i = 1 To 10
Range("A" & i).Value = "Row " & i
Next i

End Sub

If you don't know beforehand how many cells, you're going through, you may use the CountA function to find out:

i = Application.WorksheetFunction.CountA(Range("B:B"))

Or use rangeselection.row to find starting and ending row numbers and work it out...?

Probably you could use a For Each...Next - but I haven't done that for a while...


Key: Complain about this post

Write an Entry

"The Hitchhiker's Guide to the Galaxy is a wholly remarkable book. It has been compiled and recompiled many times and under many different editorships. It contains contributions from countless numbers of travellers and researchers."

Write an entry
Read more