+ Reply to Thread
Results 1 to 15 of 15

Hide non continuous rows using a macro

Hybrid View

  1. #1
    Registered User
    Join Date
    08-29-2012
    Location
    Scotland
    MS-Off Ver
    Excel 2010
    Posts
    84

    Hide non continuous rows using a macro

    Hi,

    I have recorded a macro but because my rows are not continuous it is rather jumpy when running. Is there any way to stop this? perhaps selecting all rows and hiding at the one time?
    Sub hidecostprices()
    '
    ' hidecostprices Macro
    '
    
    '
        Rows("47:63").Select
        Selection.EntireRow.Hidden = True
        Rows("66:82").Select
        Selection.EntireRow.Hidden = True
        Rows("85:101").Select
        Selection.EntireRow.Hidden = True
        Rows("104:120").Select
        Selection.EntireRow.Hidden = True
        Rows("123:139").Select
        Selection.EntireRow.Hidden = True
        Rows("142:158").Select
        Selection.EntireRow.Hidden = True
        Rows("161:177").Select
        Selection.EntireRow.Hidden = True
        
    End Sub

  2. #2
    Forum Guru JosephP's Avatar
    Join Date
    03-27-2012
    Location
    Ut
    MS-Off Ver
    2003/10
    Posts
    7,328

    Re: Hide non continuous rows using a macro

    
    Sub hidecostprices()
    '
    ' hidecostprices Macro
    '
    
    '
        Range("47:63,66:82,85:101,104:120,123:139,142:158,161:177").EntireRow.Hidden = True
        
    End Sub
    oughta be enough
    Josie

    if at first you don't succeed try doing it the way your wife told you to

  3. #3
    Registered User
    Join Date
    08-29-2012
    Location
    Scotland
    MS-Off Ver
    Excel 2010
    Posts
    84

    Re: Hide non continuous rows using a macro

    thank you!

  4. #4
    Registered User
    Join Date
    08-29-2012
    Location
    Scotland
    MS-Off Ver
    Excel 2010
    Posts
    84

    Re: Hide non continuous rows using a macro

    JosephP,

    Looking for your help on something similar please. I am looking to hide multiple rows and columns on different sheets. The code below works but again because I'm selecting the different sheets its jumping. Do you have a solution to this?
    Thanks,

    Nicola
    Sub hidecostprices()
    '
    ' hidecostprices Macro
    '
    Sheets("RC001").Select
    Range("K:R").EntireColumn.Hidden = True
    Sheets("RC003").Select
    Range("K:R").EntireColumn.Hidden = True
    Sheets("Cover Sheet").Select
    Range("47:63,66:82,85:101,104:120,123:139,142:158,161:177,180:196,199:215,218:234,237:253,256:272,275:291,294:310,313:329,332:348,351:367,370:386,389:405,408:424,427:443,446:462,465:481,484:500,503:519").EntireRow.Hidden = True
    
    End Sub

  5. #5
    Forum Guru JosephP's Avatar
    Join Date
    03-27-2012
    Location
    Ut
    MS-Off Ver
    2003/10
    Posts
    7,328

    Re: Hide non continuous rows using a macro

    Sub hidecostprices()
    '
    ' hidecostprices Macro
    '
    Sheets("RC001").Range("K:R").EntireColumn.Hidden = True
    Sheets("RC003").Range("K:R").EntireColumn.Hidden = True
    Sheets("Cover Sheet").Range("47:63,66:82,85:101,104:120,123:139,142:158,161:177,180:196,199:215,218:234,237:253,256:272,275:291,294:310,313:329,332:348,351:367,370:386,389:405,408:424,427:443,446:462,465:481,484:500,503:519").EntireRow.Hidden = True
    
    End Sub

  6. #6
    Registered User
    Join Date
    08-29-2012
    Location
    Scotland
    MS-Off Ver
    Excel 2010
    Posts
    84

    Re: Hide non continuous rows using a macro

    thanks again for the help and quick response!

  7. #7
    Registered User
    Join Date
    08-29-2012
    Location
    Scotland
    MS-Off Ver
    Excel 2010
    Posts
    84

    Re: Hide non continuous rows using a macro

    For some reason I'm now getting a 'run-time error '1004' Unable to set the Hidden property of the Range class' and the following line is highlighted? Do you know why this could be?
    Sheets("RC001").Range("K:R").EntireColumn.Hidden = True

  8. #8
    Forum Guru JosephP's Avatar
    Join Date
    03-27-2012
    Location
    Ut
    MS-Off Ver
    2003/10
    Posts
    7,328

    Re: Hide non continuous rows using a macro

    are there merged cells in the columns or is the sheet protected?

  9. #9
    Registered User
    Join Date
    08-29-2012
    Location
    Scotland
    MS-Off Ver
    Excel 2010
    Posts
    84

    Re: Hide non continuous rows using a macro

    Just realised it's when I have my vba project password protected. Is there anyway to fix this? I do not want others to view my code.

    Nicola

  10. #10
    Forum Guru JosephP's Avatar
    Join Date
    03-27-2012
    Location
    Ut
    MS-Off Ver
    2003/10
    Posts
    7,328

    Re: Hide non continuous rows using a macro

    protecting the code should not affect being able to hide columns

  11. #11
    Registered User
    Join Date
    08-29-2012
    Location
    Scotland
    MS-Off Ver
    Excel 2010
    Posts
    84

    Re: Hide non continuous rows using a macro

    Could this be why - I am using the code below to hide the cost prices then protect the workbook. When I run the lockandsave macro without running the hidecostprices it works fine and vice versa?
    Sub lockandsave()
    '
    ' lockandsave Macro
    '
    
    '
    Application.Run "hidecostprices"
    Dim sInput
    sInput = MsgBox("Are you sure you want to lock and save?", vbYesNo)
    If sInput <> vbYes Then Exit Sub
    Dim strChar As String
        Application.Run "ProtectAll"
        Range("F39").Select
    If newname = "" Then
    str1 = ActiveCell
    Else
    str1 = newname
    End If
    ck = Application.Dialogs(xlDialogSaveAs).Show(str1)
    If ck = True Then
    newname = ActiveWorkbook.Name
    End If
    End Sub

  12. #12
    Forum Guru JosephP's Avatar
    Join Date
    03-27-2012
    Location
    Ut
    MS-Off Ver
    2003/10
    Posts
    7,328

    Re: Hide non continuous rows using a macro

    yes-if you protect the sheets your other code cannot change them

  13. #13
    Registered User
    Join Date
    08-29-2012
    Location
    Scotland
    MS-Off Ver
    Excel 2010
    Posts
    84

    Re: Hide non continuous rows using a macro

    If I run the 'hidecostprices' macro before running the 'ProtectAll' macro should this not work? I thought running this at the beginning would run this first. Sorry I'm just getting started.

  14. #14
    Forum Guru JosephP's Avatar
    Join Date
    03-27-2012
    Location
    Ut
    MS-Off Ver
    2003/10
    Posts
    7,328

    Re: Hide non continuous rows using a macro

    are you sure that the sheets are not protected before you run that?

  15. #15
    Registered User
    Join Date
    08-29-2012
    Location
    Scotland
    MS-Off Ver
    Excel 2010
    Posts
    84

    Re: Hide non continuous rows using a macro

    Got it! In my first code I was hiding the cost prices then protecting. In my second code I was trying to unhide the cost prices before unprotecting. Thanks for the help again!

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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.6.0 RC 1