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.

[TABLE="width: 192"]
<tbody>[TR]
[TD="class: xl63, width: 64"]SEQ[/TD]
[TD="class: xl63, width: 64"]acc[/TD]
[TD="class: xl63, width: 64"]bsb[/TD]
[/TR]
[TR]
[TD="class: xl63, width: 64"]1[/TD]
[TD="class: xl63, width: 64"]123[/TD]
[TD="class: xl63, width: 64"]4567[/TD]
[/TR]
[TR]
[TD="class: xl63, width: 64"]bas[/TD]
[TD="class: xl63, width: 64"]456[/TD]
[TD="class: xl63, width: 64"]789[/TD]
[/TR]
[TR]
[TD="class: xl63, width: 64"]2[/TD]
[TD="class: xl63, width: 64"]123[/TD]
[TD="class: xl63, width: 64"]4567[/TD]
[/TR]
[TR]
[TD="class: xl63, width: 64"]3[/TD]
[TD="class: xl63, width: 64"]147[/TD]
[TD="class: xl63, width: 64"]78[/TD]
[/TR]
[TR]
[TD="class: xl64"][/TD]
[TD="class: xl64"][/TD]
[TD="class: xl64"][/TD]
[/TR]
[TR]
[TD="class: xl63, width: 64"]4[/TD]
[TD="class: xl63, width: 64"]474[/TD]
[TD="class: xl63, width: 64"]456[/TD]
[/TR]
[TR]
[TD="class: xl63, width: 64"]5[/TD]
[TD="class: xl63, width: 64"]741[/TD]
[TD="class: xl63, width: 64"]475[/TD]
[/TR]
</tbody>[/TABLE]

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

Which lookup functions find a value equal or greater than the lookup value?
MATCH uses -1 to find larger value (lookup table must be sorted ZA). XLOOKUP uses 1 to find values greater and does not need to be sorted.
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.

[TABLE="class: cms_table, width: 192"]
<tbody>[TR]
[TD="class: cms_table_xl63, width: 64"]SEQ[/TD]
[TD="class: cms_table_xl63, width: 64"]acc[/TD]
[TD="class: cms_table_xl63, width: 64"]bsb[/TD]
[/TR]
[TR]
[TD="class: cms_table_xl63, width: 64"]bas[/TD]
[TD="class: cms_table_xl63, width: 64"]123[/TD]
[TD="class: cms_table_xl63, width: 64"]4567[/TD]
[/TR]
[TR]
[TD="class: cms_table_xl63, width: 64"]bas[/TD]
[TD="class: cms_table_xl63, width: 64"]456[/TD]
[TD="class: cms_table_xl63, width: 64"]789[/TD]
[/TR]
[TR]
[TD="class: cms_table_xl63, width: 64"]2[/TD]
[TD="class: cms_table_xl63, width: 64"]123[/TD]
[TD="class: cms_table_xl63, width: 64"]4567[/TD]
[/TR]
[TR]
[TD="class: cms_table_xl63, width: 64"]3[/TD]
[TD="class: cms_table_xl63, width: 64"]147[/TD]
[TD="class: cms_table_xl63, width: 64"]78[/TD]
[/TR]
[TR]
[TD="class: cms_table_xl64"][/TD]
[TD="class: cms_table_xl64"][/TD]
[TD="class: cms_table_xl64"][/TD]
[/TR]
[TR]
[TD="class: cms_table_xl63, width: 64"]4[/TD]
[TD="class: cms_table_xl63, width: 64"]474[/TD]
[TD="class: cms_table_xl63, width: 64"]456[/TD]
[/TR]
[TR]
[TD="class: cms_table_xl63, width: 64"]5[/TD]
[TD="class: cms_table_xl63, width: 64"]741[/TD]
[TD="class: cms_table_xl63, width: 64"]475[/TD]
[/TR]
</tbody>[/TABLE]

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,223,227
Messages
6,170,849
Members
452,361
Latest member
d3ad3y3

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