Excel Macro - How do change my code If Cell is Empty The Code should End

Gomes1985

New Member
Joined
Jun 20, 2016
Messages
32
Hi All,

I Am reading and excel sheet using macro. I have Put a condition already if the code come across ani ISNummeric = false Skip it to next line.

I wanna know if the code comes a line where Column A B and C is empty Code should end DO Not go Beyond that row. Below is the table as per table below

Code should end after line 3.

SEQaccbsb
11234567
bas456789
21234567
314778
4474456
5741475

<tbody>
</tbody>

My Code is ..

Public Sub proIterate()
Dim RowCounter As Long
InitialRow = 2
'Write a procedure that counts the number of rows...
FinalRow = BaseSheet.Cells(BaseSheet.Rows.Count, "B").End(xlUp).Row 'This gives the number of data in the column "B"


For RowCounter = InitialRow To ThisWorkbook.Sheets("sheet1").Cells(ThisWorkbook.Sheets("sheet1").Rows.Count, "A").End(xlUp).Row ' The loop you wanted
If IsNumeric(ThisWorkbook.Sheets("sheet1").Cells(RowCounter, "A")) = True Then
'ThisWorkbook.Sheets("sheet1").Cells(RowCounter, "D") = "A" & RowCounter & " is a number"
Call proNewMacro
End If
InitialRow = InitialRow + 1
Next
MsgBox ("The End")
End Sub

Code Might need a bit of clean up Sorry about that.

Any Help would be great
 

Excel Facts

Excel Wisdom
Using a mouse in Excel is the work equivalent of wearing a lanyard when you first get to college
Code:
[color=darkblue]Public[/color] [color=darkblue]Sub[/color] proIterate()
    [color=darkblue]Dim[/color] RowCounter [color=darkblue]As[/color] [color=darkblue]Long[/color]
    InitialRow = 2
    [color=green]'Write a procedure that counts the number of rows...[/color]
    FinalRow = BaseSheet.Cells(BaseSheet.Rows.Count, "B").End(xlUp).Row    [color=green]'This gives the number of data in the column "B"[/color]
    
    [color=darkblue]For[/color] RowCounter = InitialRow [color=darkblue]To[/color] ThisWorkbook.Sheets("sheet1").Cells(ThisWorkbook.Sheets("sheet1").Rows.Count, "A").End(xlUp).Row    [color=green]' The loop you wanted[/color]
[B]        [color=darkblue]If[/color] ThisWorkbook.Sheets("sheet1").Cells(RowCounter, "A").Value = "" [color=darkblue]Then[/color] [color=darkblue]Exit[/color] [color=darkblue]For[/color][/B]
        [color=darkblue]If[/color] IsNumeric(ThisWorkbook.Sheets("sheet1").Cells(RowCounter, "A")) = [color=darkblue]True[/color] [color=darkblue]Then[/color]
            [color=green]'ThisWorkbook.Sheets("sheet1").Cells(RowCounter, "D") = "A" & RowCounter & " is a number"[/color]
            [color=darkblue]Call[/color] proNewMacro
        [color=darkblue]End[/color] [color=darkblue]If[/color]
        InitialRow = InitialRow + 1
    [color=darkblue]Next[/color]
    MsgBox ("The End")
End [color=darkblue]Sub[/color]
 
Upvote 0
Thanks for that

If
ThisWorkbook.Sheets("sheet1").Cells(RowCounter, "A").Value = "" Then Exit For

This Code actually satisfy if Column A (SEQ ) is empty only but if Column B and C is NOT empty the code will stop.

Code has to Satisfy ALL Columns A, B and C to come to an end otherwise have to continue reading as usual. Even Column A is empty

I was trying with IsEmpty but going no where so far
 
Upvote 0
Code:
With ThisWorkbook.Sheets("sheet1")
     IF .Cells(RowCounter, "A").Value = "" And _
        .Cells(RowCounter, "B").Value = "" And _
        .Cells(RowCounter, "C").Value = "" Then Exit For
End With
 
Upvote 0
I think I was too late to tell its perfect. The job Exits If I have 2 Character values in Column A

I think just a logical error or I am not using the Code at right place.

SEQaccbsb
bas1234567
bas456789
21234567
314778
4474456
5741475

<tbody>
</tbody>

Public Sub proIterate()
Dim RowCounter As Long
InitialRow = 2
'Write a procedure that counts the number of rows...
FinalRow = BaseSheet.Cells(BaseSheet.Rows.Count, "B").End(xlUp).Row 'This gives the number of data in the column "B"


For RowCounter = InitialRow To ThisWorkbook.Sheets("Sheet1").Cells(ThisWorkbook.Sheets("Sheet1").Rows.Count, "A").End(xlUp).Row ' The loop you wanted
With ThisWorkbook.Sheets("Sheet1")
If .Cells(RowCounter, "A").Value = "" And _
.Cells(RowCounter, "B").Value = "" And _
.Cells(RowCounter, "C").Value = "" Then Exit For
End With
If IsNumeric(ThisWorkbook.Sheets("Sheet1").Cells(RowCounter, "A")) = True Then
Call proNewMacro
End If
InitialRow = InitialRow + 1
Next
MsgBox ("The End")
End Sub
 
Upvote 0

Forum statistics

Threads
1,214,983
Messages
6,122,583
Members
449,089
Latest member
Motoracer88

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top