View Full Version : Solved: RowCount
Nicolaf
08-11-2011, 09:41 AM
Hi,
I am getting a Run-Time error message when I run this code.
Private Sub CommandButton1_Click()
FinalRow = Cells(Rows.Count, 1).End(x1Up).Row
For I = 2 To FinalRow
If Cells(I, 6).Value > 0 Then
Cells(I, 7).Value = "Profit"
End If
Next I
End Sub
Can someone fix it?
Thanks,
Nix
:dunno
Bob Phillips
08-11-2011, 09:55 AM
It should be xlUp not x1Up
Kenneth Hobs
08-11-2011, 09:58 AM
Always use Option Explicit as the first line of code. I use Range rather than Cell as Range will allow Intellisense to work for you. When that happens, you can see that you used x1Up rather than xLUp.
Private Sub CommandButton1_Click()
Dim FinalRow As Long, I As Long
FinalRow = Range("A" & Rows.Count).End(xlUp).Row
If FinalRow < 2 Then Exit Sub
For I = 2 To FinalRow
If Range("F" & I).Value2 > 0 Then Range("G" & I).Value2 = "Profit"
Next I
End Sub
Had you compiled the program, you would have seen the syntax error. I put a Compile button on the toolbar.
Please use VBA code tags rather than quotes or codes.
I posted this just after XLD's response.
Nicolaf
08-11-2011, 10:00 AM
Great thanks!
Will do!
Nix :hi:
Powered by vBulletin® Version 4.2.5 Copyright © 2025 vBulletin Solutions Inc. All rights reserved.