Solved

Loop until blank value in excel VBA

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

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

A little background as to how I came to I design this code: Around 5 years ago I designed an add-in that formatted Excel files to a corporate standard, applying different cell colours and font type depending on whether the cells contained inputs,…
PaperPort has a feature called the "Send To Bar". It provides a convenient, drag-and-drop interface for using other installed software, such as Microsoft Office. However, this article shows that the latest Office 2016 apps (installed with an Office …
Graphs within dashboards are meant to be dynamic, representing data from a period of time that will change each time the dashboard is updated with new data. Rather than update each graph to point to a different set within a static set of data, t…
This Micro Tutorial will demonstrate how to use longer labels with horizontal bar charts instead of the vertical column chart.

708 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

15 Experts available now in Live!

Get 1:1 Help Now