Results 1 to 4 of 4

Thread: End Loop on Empty Cell

  1. #1

    Thread Starter
    New Member
    Join Date
    Apr 2013
    Posts
    3

    End Loop on Empty Cell

    Hi all,

    I'm having some issues with ending a loop function when no data is populated. Currently the cell I'm targeting has a formula within it that is blank ("") unless data is populated. The below script is what I have put together, but it continues to run all the way to the end, thus providing empty rows of data in the report. I would ideally like it to stop and move on to the next part of the script when blank cells are seen. Any advice would be much appreciated.

    Thank you

    Dim Txt As String
    Dim RepDate As Date
    Dim wks As Worksheet
    Dim CRow As Integer

    Set wks = Worksheets("Mailer")

    RepDate = Date

    Txt = Txt & wks.Cells(12, 3) & vbCrLf
    Txt = Txt & wks.Cells(13, 3) & vbCrLf
    Txt = Txt & wks.Cells(13, 4) & vbCrLf
    Txt = Txt & wks.Cells(13, 5) & vbCrLf
    Txt = Txt & wks.Cells(13, 6) & vbCrLf
    Txt = Txt & wks.Cells(13, 7) & vbCrLf
    Txt = Txt & wks.Cells(13, 8) & vbCrLf & vbCrLf

    CRow = 14

    Do While CRow < 20
    'If wks.Cells(5, 2) <> 0 Then
    'Txt = Txt & "GLC Report" & vbCrLf



    Txt = Txt & wks.Cells(12, 3)
    Txt = Txt & wks.Cells(CRow, 2) & vbCrLf
    Txt = Txt & wks.Cells(CRow, 3) & vbCrLf
    Txt = Txt & wks.Cells(CRow, 4) & vbCrLf
    Txt = Txt & wks.Cells(CRow, 5) & vbCrLf
    Txt = Txt & wks.Cells(CRow, 6) & vbCrLf
    Txt = Txt & wks.Cells(CRow, 7) & vbCrLf
    Txt = Txt & wks.Cells(CRow, 8) & vbCrLf & vbCrLf
    Txt = Txt
    'End If

    CRow = CRow + 1
    Loop


    Gather_Open_Data = Txt
    Set wks = Nothing

    End Function

  2. #2
    I don't do your homework! opus's Avatar
    Join Date
    Jun 2000
    Location
    Good Old Europe
    Posts
    3,863

    Re: End Loop on Empty Cell

    Welcome to VBForums
    I guess your question is targeting Excel-VBA, so it would be better palced into the Office-Development-Section of VBF.
    In the code posted there is no line which is checking for an empty cell?
    Try to use code-tags, that will make reading easier
    You're welcome to rate this post!
    If your problem is solved, please use the Mark thread as resolved button


    Wait, I'm too old to hurry!

  3. #3
    I'm about to be a PowerPoster! Joacim Andersson's Avatar
    Join Date
    Jan 1999
    Location
    Sweden
    Posts
    14,649

    Re: End Loop on Empty Cell

    Moved to the Office Development forum.

  4. #4

    Thread Starter
    New Member
    Join Date
    Apr 2013
    Posts
    3

    Re: End Loop on Empty Cell

    Thank you for your replies, I'll move to the Office Development forum.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width