+ Reply to Thread
Page 2 of 2 FirstFirst 12
Results 16 to 20 of 20

Thread: Run macro until the end of the sheet

  1. #16
    Registered User
    Join Date
    09-28-2010
    Location
    Latvia
    MS-Off Ver
    Excel 2007/2010
    Posts
    18

    Re: Run macro until the end of the sheet

    One more question - can I make the loop end after the last row with data?

    Sub HideRows()
        BeginRow = 1
        EndRow = 60
        ChkCol = 4
        ChkCol2 = 6
        
        Sheets("27.09.-03.10.").Select
        Cells.Select
        Cells.EntireRow.AutoFit
    
        For RowCnt = BeginRow To EndRow
            If Cells(RowCnt, ChkCol).Value = 0 And Cells(RowCnt, ChkCol2).Value = 0 Then
                Cells(RowCnt, ChkCol).EntireRow.Hidden = True
            End If
        Next RowCnt
    End Sub

  2. #17
    Forum Guru JBeaucaire's Avatar
    Join Date
    03-21-2008
    Location
    Bakersfield, CA
    MS-Off Ver
    2010
    Posts
    19,226

    Re: Run macro until the end of the sheet

    You should refer to solutions already given to you. Post #7 shows several ways to determine your EndRow dynamically. Options 1 and 2 seem perfectly suited. Apply one of those instead of hardcoding the EndRow value.
    _________________
    Microsoft MVP 2010 - Excel
    Visit: Jerry Beaucaire's Excel Files & Macros

    If you've been given good help, use the icon below to give reputation feedback, it is appreciated.
    Always put your code between code tags. [CODE] your code here [/CODE]

    “None of us is as good as all of us” - Ray Kroc
    “Actually, I *am* a rocket scientist.” - JB (little ones count!)

  3. #18
    Registered User
    Join Date
    09-28-2010
    Location
    Latvia
    MS-Off Ver
    Excel 2007/2010
    Posts
    18

    Re: Run macro until the end of the sheet

    Quote Originally Posted by JBeaucaire View Post
    You should refer to solutions already given to you. Post #7 shows several ways to determine your EndRow dynamically. Options 1 and 2 seem perfectly suited. Apply one of those instead of hardcoding the EndRow value.
    Sorry again but my limited knowledge prevents me from writing my own code so i tinker with pieces of code found in the Internet and recorded in Excel.
    It seems to me that these solutions won't work for my existing code, but I have no clue as to how to rewrite it.

  4. #19
    Forum Guru JBeaucaire's Avatar
    Join Date
    03-21-2008
    Location
    Bakersfield, CA
    MS-Off Ver
    2010
    Posts
    19,226

    Re: Run macro until the end of the sheet

    You have:
    EndRow = 60

    You substitute your hardcoded "60" with the technique I've shown you post #7.

    EndRow = Cells.Find("*", Cells(Rows.Count, Columns.Count), SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row
    _________________
    Microsoft MVP 2010 - Excel
    Visit: Jerry Beaucaire's Excel Files & Macros

    If you've been given good help, use the icon below to give reputation feedback, it is appreciated.
    Always put your code between code tags. [CODE] your code here [/CODE]

    “None of us is as good as all of us” - Ray Kroc
    “Actually, I *am* a rocket scientist.” - JB (little ones count!)

  5. #20
    Registered User
    Join Date
    09-28-2010
    Location
    Latvia
    MS-Off Ver
    Excel 2007/2010
    Posts
    18

    Re: Run macro until the end of the sheet

    Thank you very much! Solved!

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.2.0