|
-
Apr 22nd, 2013, 09:45 AM
#1
Thread Starter
New Member
End loop when empty row/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
-
Apr 23rd, 2013, 01:23 AM
#2
Re: End loop when empty row/cell
I don't see any line where you are checking for an empty cell?
The code would be like
Code:
If wks.Cells(CRow,1).Value="" Then
..
End If
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!
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|