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
Solved

Loop until blank value in excel VBA

Posted on 2011-03-19
4
362 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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

Microsoft Office Picture Manager is not included in Office 2013. This comes as a shock to users upgrading from earlier versions of Office, such as 2007 and 2010, where Picture Manager was included as a standard application. This article explains how…
My experience with Windows 10 over a one year period and suggestions for smooth operation
This Micro Tutorial demonstrate the bugs in Microsoft Excel for Mac with Pivot Charts.
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

809 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