ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Discussion (Misc queries) (https://www.excelbanter.com/excel-discussion-misc-queries/)
-   -   Loop (https://www.excelbanter.com/excel-discussion-misc-queries/259167-loop.html)

Christina

Loop
 
I have a macro which loops and performs the functions. However it goes
around and does not stop. How do I tell it Do until there is no data in cell
or it reaches the end of data in the column.


Thanks
Cristina

Gary''s Student

Loop
 
Let's say we are processing data in oclumn C and we want to stop at either
the first empty cell in column C or the last value in column C

Sub Crissy()
Dim C As Range, r As Range
Set C = Range("C:C")
LastRow = Cells(Rows.Count, "C").End(xlUp).Row
For i = 1 To LastRow
If IsEmpty(Cells(i, "C").Value) Then Exit Sub
MsgBox Cells(i, "C").Value
Next
End Sub

So we both determine the last row and also look for the first empty as well.
--
Gary''s Student - gsnu201001


"Christina" wrote:

I have a macro which loops and performs the functions. However it goes
around and does not stop. How do I tell it Do until there is no data in cell
or it reaches the end of data in the column.


Thanks
Cristina



All times are GMT +1. The time now is 05:14 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com