Consulting

Results 1 to 4 of 4

Thread: Solved: RowCount

  1. #1

    Solved: RowCount

    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

  2. #2
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    It should be xlUp not x1Up
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  3. #3
    VBAX Guru Kenneth Hobs's Avatar
    Joined
    Nov 2005
    Location
    Tecumseh, OK
    Posts
    4,956
    Location
    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.

    [vba]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[/vba]
    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.

  4. #4
    Great thanks!

    Will do!
    Nix

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •