Row.count does not work

whcmelvin

Board Regular
Joined
Jul 27, 2011
Messages
82
Hi, i have a vba code with row.count. it does not increase the row count. My test@hotmail.com is n1=3. But n1 always stops at 2. Please help
Code:
        Sheets("Account Details").Visible = True
        Sheets("Account Details").Select
        NextRow1 = Application.WorksheetFunction.CountA(Range("A:A")) + 1
        Set r1 = Range(Cells(1, 1), Cells(NextRow1, 1))
        For n1 = 2 To r1.Rows.Count
                
       
        
            If Cells(n1, 1).Value = "test@hotmail.com" Then
            MsgBox "HO"
            Else
            MsgBox "hi"

            End If

        
        Next n1
 

Excel Facts

Control Word Wrap
Press Alt+Enter to move to a new row in a cell. Lets you control where the words wrap.
It's because you're using a messagebox and you're calling the code is more complicated than it needs to be.
You must click on the msgBox to go onto the next value.

Just replace the for loop with this
Code:
For n1 = 2 To Sheets("Account Details").Cells(Rows.Count, 1).End(xlUp).Row
 
Upvote 0
Hi, whcmelvin,

or use a For Each to loop through the range r1:

Code:
Sub bla()
Dim NextRow1 As Long
Dim r1 As Range
Dim rngCell As Range

With Sheets("Account Details")
    .Visible = True
    .Select
End With

NextRow1 = Application.WorksheetFunction.CountA(Range("A:A")) + 1

Set r1 = Range(Cells(1, 1), Cells(NextRow1, 1))
For Each rngCell In r1
    If rngCell.Value = "test@hotmail.com" Then
        Debug.Print "HO"
    Else
        Debug.Print "hi"
    End If
Next rngCell

End Sub
Ciao,
Holger
 
Upvote 0
Thanks lots. it works. Btw, does you all know if excel could insert those java charts that in in the internet?
 
Upvote 0

Forum statistics

Threads
1,224,595
Messages
6,179,799
Members
452,943
Latest member
Newbie4296

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