Solved

Loop until blank value in excel VBA

Posted on 2011-03-19
4
377 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

Question has a verified solution.

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

In Part II of this series, I will discuss how to identify all open instances of Excel and enumerate the workbooks, spreadsheets, and named ranges within each of those instances.
I was prompted to write this article after the recent World-Wide Ransomware outbreak. For years now, System Administrators around the world have used the excuse of "Waiting a Bit" before applying Security Patch Updates. This type of reasoning to me …
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 …
This Micro Tutorial will demonstrate how to use longer labels with horizontal bar charts instead of the vertical column chart.

691 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