Macro command to move cell selection

D

DOOGIE

I am writing a macro for a spreadsheet where I have values stored in one
column. I want to run a loop where each time the loop runs, I select each
cell in the column. For example, my values are stored in column A, cells 1
through 7. On loop 1 I want to select cell A1, loop 2 select cell A2, loop 3
select A3 and so on. How can I set this up in a macro to increment cell
selection as I move through my loop?
 
R

Ryan H

I'm really not sure whay you can do with this, but is this what you are
wanting?

Sub SelectionLoop()

Dim i As Long

For i = 1 To 7
Cells(i, "A").Select
Next i

End Sub

Hope this helps! If so, please click "YES" below.
 
F

fisch4bill

Sub DoSomething()
Dim X as Long

For X = 1 To 7 'or any number that addresses the whole range
Range("A" & X).Select

.. . . your value manipulation code goes here

Next X
End Sub

HTH
 
J

Jacob Skaria

I am sure you are looking for something else and you dont need to really
select the cell to acheive that. Go through the below code to see how to get
the cell value from any row during this loop.


Sub Macro1()
Dim cell As Range
For Each cell In Range("A1:A7")

'cell value
MsgBox cell.Value
'cell value of same row 1st column to the right
MsgBox cell.Offset(, 1).Value, , "ColB value of the same row"

'Refer another column in the same row 2nd col in the same row
MsgBox cell.Offset(, 2).Value, , "ColC value of the same row"
'OR
MsgBox Range("C" & cell.Row)

'select the cell
cell.Select

Next
End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top