Solved

Loop until blank value in excel VBA

Posted on 2011-03-19
4
351 Views
Last Modified: 2012-05-11
Hi there,

I ahve the following loop in VBA, but I want to change it so that it finishes whent he first blank cell is hit in the A collumn. THe rowsa are inserted dynamically, so it could be 10 or 100 depending on the sheet. This is what I have so far


Sub GenSheets()


Dim rng    As Range
    Dim cl     As Range
    With Sheets("Quotation")
        Set rng = .Range(.Cells(6, 1), .Cells(.Rows.Count, 1).End(xlUp))
        For Each cl In rng
            
            MsgBox (cl.Value)
            
        Next cl
    End With
    
End Sub

Open in new window

0
Comment
Question by:wellso
  • 2
4 Comments
 
LVL 24

Expert Comment

by:jimyX
ID: 35172192
You match as follows:
If Not YouRange Is Nothing Then
0
 
LVL 2

Author Comment

by:wellso
ID: 35172231
Could you give me an example how I break out from the loop with it?
0
 
LVL 81

Accepted Solution

by:
zorvek (Kevin Jones) earned 500 total points
ID: 35172323
Sub GenSheets()


Dim rng    As Range
    Dim cl     As Range
    With Sheets("Quotation")
        Set rng = .Range(.Cells(6, 1), .Cells(.Rows.Count, 1).End(xlUp))
        For Each cl In rng
            If Len(cl) = 0 Then Exit For
            MsgBox (cl.Value)
           
        Next cl
    End With
   
End Sub

Kevin
0
 
LVL 2

Author Closing Comment

by:wellso
ID: 35172334
cheers buddy
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Entering a date in Microsoft Access can be tricky. A typo can cause month and day to be shuffled, entering the day only causes an error, as does entering, say, day 31 in June. This article shows how an inputmask supported by code can help the user a…
Freeze panes is an option within all variants of Excel to enable parts of a sheet to remain stationary when the cursor is in another part of the sheet. This is a very useful feature which is overlooked or under used.
Learn how to make your own table of contents in Microsoft Word using paragraph styles and the automatic table of contents tool. We'll be using the paragraph styles in Word’s Home toolbar to help you create a table of contents. Type out your initial …
Many functions in Excel can make decisions. The most simple of these is the IF function: it returns a value depending on whether a condition you describe is true or false. Once you get the hang of using the IF function, you will find it easier to us…

867 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now