Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

  • Congratulations waross on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

VB-ITERATION

Status
Not open for further replies.

L775

Structural
Feb 4, 2001
48
0
0
US
How do I stop AN iteration when it reaches the end of a group of occupied cells filled with the IDENTICAL text (i.e. B277) in a column?

I want it to stop at the end of the list. HOW does it know that the next
cell is empty so it will not error or use an empty cell.
the length of the list in a column or number of rows varies for different
groups that the routine or loop neet to operate on. thank you for your help.
I know there is a way of doing.


 
Replies continue below

Recommended for you

Start from the first cell and use a Do Loop, increementing the row counter and checking for the appropriate value:
Code:
Private Sub CommandButton1_Click()
a = 1
Do While ActiveSheet.Cells(a, 1) = "b277"
Cells(a, 2) = a ' or do whatever you need here
a = a + 1
Loop
MsgBox a - 1 & " Cells affected"
End Sub

The example starts looking at A1 and goes down until the cell value changes. Change the initial value of a to start at a different row. The second value in the first Cells function (1 in this case) sets the column to search

Good Luck
johnwm
________________________________________________________
To get the best from these forums read faq731-376 before posting

UK steam enthusiasts:
 
Status
Not open for further replies.
Back
Top