Excel Macro - If Cell contains a character go to the next row and STOP when Empty

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(SEQ)

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
 

Trebor76

Well-known Member
Joined
Jul 23, 2007
Messages
4,467
Hello Gomes1985 (again),

I'm not too sure about some of your code but you can use the following to stop the macro if there's nothing in columns A, B & C:

Code:
If Len(.Cells(RowCounter, "A")) = 0 And _
Len(.Cells(RowCounter, "B")) = 0 And _
Len(.Cells(RowCounter, "C")) = 0 Then Exit For
Regards,

Robert
 

Gomes1985

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

Sorry I had to come back again Code it right.

its logical error.

What happens is since its to String It does not go to 3 rd row for some reason.

I might have to pull apart

With ThisWorkbook.Sheets("Sheet1")
If .Cells(RowCounter, "A").Value = "" And _
.Cells(RowCounter, "B").Value = "" And _
.Cells(RowCounter, "C").Value = "" Then Exit For
End With

Code checks for Numerics and work fine

even skips. Code is working fine but Loop Exits at Row 3

What should happen is it should read

21234567
314778

<tbody>
</tbody>
Then Exit the loop.

Code is correct its Logical error I think

Funny thing is if I have Only 2 records it works too

p.s - Its not a duplicate post Its slightly different issue
 

MARK858

MrExcel MVP
Joined
Nov 12, 2010
Messages
11,487
Office Version
365, 2010
Platform
Windows, Mobile
p.s - Its not a duplicate post Its slightly different issue
How is post #1 of this thread different to the question you asked in post #6 of the other thread :confused:
 
Last edited:

Forum statistics

Threads
1,082,126
Messages
5,363,317
Members
400,725
Latest member
excelingtolearn

Some videos you may like

This Week's Hot Topics

  • populate from drop list with multiple tables
    Hi All, i have a drop list that displays data, what i want is when i select one of those from the list to populate text from different tables on...
  • Find list of words from sheet2 in sheet1 before a comma and extract text vba
    Hi Friends, Trying to find the solution on my task. But did not find suitable one to the need. Here is my query and sample file with details...
  • Dynamic Formula entry - VBA code sought
    Hello, really hope one of you experts can help with this - i've spent hours on this and getting no-where. .I have a set of data (more rows than...
  • Listbox Header
    Have a named range called "AccidentsHeader" Within my code I have: [CODE]Private Sub CommandButton1_Click() ListBox1.RowSource =...
  • Complex Heat Map using conditional formatting
    Good day excel world. I have a concern. Below link have a list of countries that carries each country unique data. [URL...
  • Conditional formatting
    Hi good morning, hope you can help me please, I have cells P4:P54 and if this cell is equal to 1 then i want row O to say "Fully Utilised" and to...
Top