Consulting

Results 1 to 10 of 10

Thread: Getting The Cells to focus!!! Using FOR LOOP to find and select only the last row)

  1. #1
    VBAX Regular
    Joined
    Apr 2018
    Posts
    44
    Location

    Getting The Cells to focus!!! Using FOR LOOP to find and select only the last row)

    I'm using MS Office 2010. win7

    Somehow I've gotten the selected new rows to focus rather than the most recent one.

    I need to use FOR Loop to find and select only the last row.

    this what i have so far:
    Option Explicit
    Private Sub CommandButton1_Click()
    Dim pass As String
        pass = "abc1234"
        ActiveSheet.Protect Password:=pass, UserInterFaceOnly:=True
    
    
    With Range("A17:A42").SpecialCells(xlVisible).Areas(1)
          .Offset(.Count).Resize(1).EntireRow.Hidden = False
       
       ActiveSheet.Range("b19:d42").Select
       
       End With
    End Sub
    Thankful for any and all help!!! Thanks a Million
    Last edited by xld; 06-13-2018 at 11:21 AM. Reason: Added code tags

  2. #2
    VBAX Regular
    Joined
    Apr 2018
    Posts
    44
    Location
    Do i use something like:

    FOR counter = start TO end [Step increment]
    {...statements...}
    NEXT [counter];

  3. #3
    Distinguished Lord of VBAX VBAX Grand Master xld's Avatar
    Joined
    Apr 2005
    Posts
    24,902
    Location
    Use

    Cells(Rows.count, "A").End(xlUp).EntireRow.Select
    ____________________________________________
    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

  4. #4
    VBAX Regular
    Joined
    Apr 2018
    Posts
    44
    Location
    Quote Originally Posted by xld View Post
    Use

    Cells(Rows.count, "A").End(xlUp).EntireRow.Select
    i got an error when i added to what i got


    Private Sub CommandButton1_Click()
    Dim pass As String
    pass = "nh1234"
    ActiveSheet.Protect Password:=pass, UserInterFaceOnly:=True


    With Range("A17:A42").SpecialCells(xlVisible).Areas(1)
    .Offset(.Count).Resize(1).EntireRow.Hidden = False

    Cells(Rows.Count, "A17:A42").End(xlUp).EntireRow.Select

    ActiveSheet.Range("b19:d42").Select

    End With
    End Sub

  5. #5
    Distinguished Lord of VBAX VBAX Grand Master xld's Avatar
    Joined
    Apr 2005
    Posts
    24,902
    Location
    Not sure what the specialcells is all about, but maybe it should be
    Private Sub CommandButton1_Click()
     Dim pass As String
     pass = "nh1234"
     ActiveSheet.Protect Password:=pass, UserInterFaceOnly:=True
    
    
     With Range("A17:A42").SpecialCells(xlVisible).Areas(1)
     
         .Offset(.Count).Resize(1).EntireRow.Hidden = False
     End With
    
     Cells(Rows.Count, "A").End(xlUp).EntireRow.Select 
    End Sub
    ____________________________________________
    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

  6. #6
    VBAX Regular
    Joined
    Apr 2018
    Posts
    44
    Location
    i have some hidden rows and the focus is not focusing on the the last row in the rows. it focus on the bottom of the sheet.

  7. #7
    Distinguished Lord of VBAX VBAX Grand Master xld's Avatar
    Joined
    Apr 2005
    Posts
    24,902
    Location
    Maybe post your workbook, I am working in the dark.
    ____________________________________________
    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

  8. #8
    VBAX Regular
    Joined
    Apr 2018
    Posts
    44
    Location
    Quote Originally Posted by xld View Post
    Maybe post your workbook, I am working in the dark.
    sorry for the late and long reply. i had to get some sleep lol. i attached the workbook.
    Attached Files Attached Files
    Last edited by Ladyj205; 06-14-2018 at 11:43 AM.

  9. #9
    Distinguished Lord of VBAX VBAX Grand Master xld's Avatar
    Joined
    Apr 2005
    Posts
    24,902
    Location
    I am not totally sure what should happen. Should a new line be inserted at row 42, but formatted as per row 41, and wit the next id? Should it be hidden or not? Will all rows other than id 1 always be hidden?
    ____________________________________________
    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

  10. #10
    VBAX Regular
    Joined
    Apr 2018
    Posts
    44
    Location
    Quote Originally Posted by xld View Post
    I am not totally sure what should happen. Should a new line be inserted at row 42, but formatted as per row 41, and wit the next id? Should it be hidden or not? Will all rows other than id 1 always be hidden?
    I need to use FOR Loop to find and select only the last row. I just have my original vba code in. Sorry it should be hidden. When the user click on the new row button it shows one row at a time.

Posting Permissions

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