+ Reply to Thread
Results 1 to 5 of 5

Excel VBA Code + Error when trying to run multiple scripts in one work sheet.

  1. #1
    Registered User
    Join Date
    10-30-2013
    Location
    Birmingham, Alabama
    MS-Off Ver
    Excel 2007
    Posts
    4

    Excel VBA Code + Error when trying to run multiple scripts in one work sheet.

    Dear All,

    Thank you in advance for your time.
    I am having trouble with a code that i compiled that is supposed to do 4 things in successive order in a worksheet that I have. The problem is that it is not working past the first code.
    In order of desired operations:
    Code 1 - Code 1 is supposed to look at the value in a drop down (Yes or No) and hide specified rows. This code works and hides the rows are requested.
    Code 2 - Code 2 is supposed to look at another drop down and say if No, hide the following rows. This code works too, if i use it just by itself
    Code 3 - Code 3 is supposed to look at a third drop down (Yes or No) and hide rows 44 : 45, and rows 50 : 59
    Code 4 - Code 4 is supposed to look at a numerical value in a cell, and then based on this numerical value, do the following:

    If the numerical value is 1, then hide rows 50 :59;
    If the numerical value is 2, then hide rows 51 : 59:
    If the numerical value is 3, then hide rows 52:59……………

    Up to if the numerical value is 10, then no rows.

    The code that I constructed is below, however only the first code is working.
    Please review and advise what I am doing wrong.
    I have researched possible answers, but they all return errors when I try to incorporate them into my code.

    Thank you all once again and I appreciate any help.


    -Warm regards,

    Blckhandsid3


    Aforementioned code:

    Please Login or Register  to view this content.
    Option Explicit
    Please Login or Register  to view this content.
    Please Login or Register  to view this content.
    Private Sub worksheet_Change(ByVal Target As Range)
    Call Script1(Target)
    Call Script2(Target)
    all Script3(Target)
    Call Script4(Target)
    End Sub
    Please Login or Register  to view this content.
    Please Login or Register  to view this content.
    Private Sub Script1(ByVal Target As Range)
    If Target.Address = "$B$24" Then
    If UCase(Range("B24").Value) = "YES" Then
    Rows("25:41").EntireRow.Hidden = False
    ElseIf UCase(Range("B24").Value) = "NO" Then
    Rows("25:41").EntireRow.Hidden = True
    End If
    End If
    End Sub
    Please Login or Register  to view this content.
    Please Login or Register  to view this content.
    Private Sub Script2(ByVal Target As Range)
    If Target.Address = "$B$25" Then
    If UCase(Range("B25").Value) = "YES" Then
    Rows("36:40").EntireRow.Hidden = False
    ElseIf UCase(Range("B25").Value) = "NO" Then
    Rows("36:40").EntireRow.Hidden = True
    End If
    End If
    End Sub
    Please Login or Register  to view this content.
    Please Login or Register  to view this content.
    Private Sub Script3(ByVal Target As Range)
    If Target.Address = "$B$43" Then
    If UCase(Range("B43").Value) = "YES" Then
    Rows("44:59").EntireRow.Hidden = False
    ElseIf UCase(Range("B43").Value) = "NO" Then
    Rows("44:45").EntireRow.Hidden = True
    Rows("50:59").EntireRow.Hidden = True
    End If
    End If
    End Sub
    Please Login or Register  to view this content.
    Please Login or Register  to view this content.
    Private Sub Script4(ByVal Target As Range)
    If Intersect(Target, Range("B44")) Then
    Exit Sub
    Select Case Target.Value
    Case 1
    Range("44:49").EntireRow.Hidden = False
    Range("50:59").EntireRow.Hidden = True
    Case 2
    Range("44:50").EntireRow.Hidden = False
    Range("51:59").EntireRow.Hidden = True
    Case 3
    Range("44:51").EntireRow.Hidden = False
    Range("52:59").EntireRow.Hidden = True
    Case 4
    Range("44:52").EntireRow.Hidden = False
    Range("53:59").EntireRow.Hidden = True
    Case 5
    Range("44:53").EntireRow.Hidden = False
    Range("54:59").EntireRow.Hidden = True
    Case 6
    Range("44:54").EntireRow.Hidden = False
    Range("55:59").EntireRow.Hidden = True
    Case 7
    Range("44:55").EntireRow.Hidden = False
    Range("56:59").EntireRow.Hidden = True
    Case 8
    Range("44:56").EntireRow.Hidden = False
    Range("57:59").EntireRow.Hidden = True
    Case 9
    Range("44:57").EntireRow.Hidden = False
    Range("58:59").EntireRow.Hidden = True
    Case 10
    Range("44:58").EntireRow.Hidden = False
    Range("51:59").EntireRow.Hidden = True
    Case 11
    Range("44:59").EntireRow.Hidden = False
    Range("60:61").EntireRow.Hidden = True
    End Select
    End If
    End Sub
    Please Login or Register  to view this content.
    Last edited by blckhandsid3; 11-06-2013 at 02:53 PM. Reason: Attempted to Add code tags using [php]

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

    Re: Excel VBA Code + Error when trying to run multiple scripts in one work sheet.

    Could you please enclose the code in code tags?

    Then it'll be easier to read.

    By the way, why 4 different subs all taking the same argument?

    They could all be combined in the Worksheet_Change event.
    If posting code please use code tags, see here.

  3. #3
    Registered User
    Join Date
    10-30-2013
    Location
    Birmingham, Alabama
    MS-Off Ver
    Excel 2007
    Posts
    4

    Re: Excel VBA Code + Error when trying to run multiple scripts in one work sheet.

    Quote Originally Posted by Norie View Post
    Could you please enclose the code in code tags?

    Then it'll be easier to read.

    By the way, why 4 different subs all taking the same argument?

    They could all be combined in the Worksheet_Change event.
    Norie,
    Thank you for your response. I attempted to repost the code using the [php] code tag per your link, i believe it should be showing per your suggestion?
    Thank you once again.

  4. #4
    Registered User
    Join Date
    10-30-2013
    Location
    Birmingham, Alabama
    MS-Off Ver
    Excel 2007
    Posts
    4

    Re: Excel VBA Code + Error when trying to run multiple scripts in one work sheet.

    Norie,

    Can you please check to see if the code has been properly spaced out for easier reading?
    furthermore, can you please explain in detail how i would go about combining the four into one worksheet_change script?
    Thank you.

  5. #5
    Registered User
    Join Date
    10-30-2013
    Location
    Birmingham, Alabama
    MS-Off Ver
    Excel 2007
    Posts
    4

    Re: Excel VBA Code + Error when trying to run multiple scripts in one work sheet.

    Thank you all. fixed it my self. The problem was that i was linking the triggering value to data from other sheets instead of drop downs on the sheets were the macros were.
    Thanks neverthless.

+ 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. Macros stop to work when work sheet is protected. Run time error 1004
    By sellim in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 10-18-2012, 01:14 AM
  2. Replies: 0
    Last Post: 06-28-2012, 01:08 AM
  3. coding error when trying to chanage code to work on same sheet but different area
    By jabjab in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 12-07-2011, 12:45 PM
  4. How to run macro code and work on excel sheet simultaneously
    By sharmanjali87 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 11-29-2010, 03:43 AM
  5. For a website, are Excel scripts better than other programming language scripts?
    By Advice Pro in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 05-01-2009, 02:07 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