+ Reply to Thread
Results 1 to 5 of 5

Need to add to an event in VBA and can't

  1. #1
    Registered User
    Join Date
    11-13-2012
    Location
    Minneapolis, MN
    MS-Off Ver
    Excel 2010
    Posts
    21

    Need to add to an event in VBA and can't

    Hello! I have an event in VBA that is hiding columns and rows based on a users input into a cell (in this case B3). See code below:

    Private Sub Worksheet_Change(ByVal Target As Range)
    Columns("C:R").EntireColumn.Hidden = False
    Rows("9:57").EntireRow.Hidden = False
    If Target.Address = "$B$3" Then
    Select Case Target.Value
    Case Is = "Sunday"
    Columns("E:R").EntireColumn.Hidden = True
    Rows("41:46").EntireRow.Hidden = True
    Case Is = "Monday"
    Columns("C:D").EntireColumn.Hidden = True
    Columns("G:R").EntireColumn.Hidden = True
    Rows("43:46").EntireRow.Hidden = True
    Case Is = "Tuesday"
    Columns("C:F").EntireColumn.Hidden = True
    Columns("I:R").EntireColumn.Hidden = True
    Rows("41:42").EntireRow.Hidden = True
    Rows("44:46").EntireRow.Hidden = True
    Case Is = "Wednesday"
    Columns("C:H").EntireColumn.Hidden = True
    Columns("K:R").EntireColumn.Hidden = True
    Rows("41:43").EntireRow.Hidden = True
    Rows("45:46").EntireRow.Hidden = True
    Case Is = "Thursday"
    Columns("C:J").EntireColumn.Hidden = True
    Columns("M:R").EntireColumn.Hidden = True
    Rows("41:44").EntireRow.Hidden = True
    Rows("46").EntireRow.Hidden = True
    Case Is = "Friday"
    Columns("C:L").EntireColumn.Hidden = True
    Columns("O:R").EntireColumn.Hidden = True
    Rows("41:45").EntireRow.Hidden = True
    Case Is = "Saturday"
    Columns("C:N").EntireColumn.Hidden = True
    Columns("Q:R").EntireColumn.Hidden = True
    Rows("41:46").EntireRow.Hidden = True

    End Select

    End If

    End Sub

    I want to add something additional to the event but keep getting an error. I want to hide certain rows based on values entered in B4 as well, but cant seem to get the code right. Any help would be appreciated.

  2. #2
    Forum Guru
    Join Date
    03-02-2006
    Location
    Los Angeles, Ca
    MS-Off Ver
    Win10/MSO2016
    Posts
    12,996

    Re: Need to add to an event in VBA and can't

    Your post does not comply with Rule 3 of our Forum RULES. Use code tags around code.

    Posting code between [CODE]Please [url=https://www.excelforum.com/login.php]Login or Register [/url] to view this content.[/CODE] tags makes your code much easier to read and copy for testing, it also maintains VBA formatting.

    Highlight your code and click the # icon at the top of your post window. More information about these and other tags can be found here



    (This thread should receive no further responses until this moderation request is fulfilled, as per Forum Rule 7)
    Ben Van Johnson

  3. #3
    Registered User
    Join Date
    11-13-2012
    Location
    Minneapolis, MN
    MS-Off Ver
    Excel 2010
    Posts
    21

    Re: Need to add to an event in VBA and can't

    Please Login or Register  to view this content.

  4. #4
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,646

    Re: Need to add to an event in VBA and can't

    You should just be able to add the code for B4 after End If.
    If posting code please use code tags, see here.

  5. #5
    Registered User
    Join Date
    11-13-2012
    Location
    Minneapolis, MN
    MS-Off Ver
    Excel 2010
    Posts
    21

    Re: Need to add to an event in VBA and can't

    I got it! Thank you all!

    Bryan

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. [SOLVED] Userform multipage control - exit event not firing or event order
    By jane serky in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 06-14-2013, 10:23 AM
  2. Deactivate event appears to be overriding next activate event
    By ezrizer in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 06-01-2013, 10:15 AM
  3. Replies: 4
    Last Post: 11-07-2012, 04:02 PM
  4. How to prevent SelectionChange event firing before Change event?
    By franklyn in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 06-29-2012, 05:17 AM
  5. How to trap delete row event and hide column event?
    By Alan in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 04-26-2005, 12:06 PM

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