+ Reply to Thread
Results 1 to 11 of 11

Debug code

Hybrid View

Human2014 Debug code 01-03-2016, 05:34 PM
gmr4evr1 Re: Debug code 01-03-2016, 05:43 PM
gmr4evr1 Re: Debug code 01-03-2016, 05:49 PM
Human2014 Re: Debug code 01-03-2016, 06:05 PM
gmr4evr1 Re: Debug code 01-03-2016, 06:23 PM
Human2014 Re: Debug code 01-03-2016, 06:33 PM
gmr4evr1 Re: Debug code 01-03-2016, 06:45 PM
Human2014 Re: Debug code 01-03-2016, 06:47 PM
gmr4evr1 Re: Debug code 01-03-2016, 07:18 PM
Human2014 Re: Debug code 01-03-2016, 07:22 PM
gmr4evr1 Re: Debug code 01-03-2016, 07:27 PM
  1. #1
    Registered User
    Join Date
    10-14-2014
    Location
    USA
    MS-Off Ver
    2010
    Posts
    98

    Debug code

    Hello everyone,

    I am trying to combine two subs but I get an error when the second one starts.

    The error starts in the line where I have the bold with red

    Can someone help?

    Sub Refresh()
    
    Dim X As Variant
    Dim PW As String
    
    PW = InputBox("Please enter password below", "Password", "")
    
    If PW <> "SALARY" Then
            MsgBox "Incorrect Password"
            Exit Sub
    Else
    
    application.ScreenUpdating = False
    Sheets("Finess-Actuals").Visible = True
    
    Sheets("Finess-Actuals").Select
    Range("A2:AL290").Select
    
    Sheets("Refresh & Upload").Select
    
    Sheets("Finess-Actuals").Visible = xlSheetVeryHidden
    application.ScreenUpdating = True
    
    Sheets("Finess-Budget").Select
    Range("A2:BO290").Select
    
    Sheets("Finess-Budget").Visible = xlSheetVeryHidden
    application.ScreenUpdating = True
    
    MsgBox "Your Budget Refresh is Complete!"
    
    End If
    
    End Sub

  2. #2
    Forum Expert gmr4evr1's Avatar
    Join Date
    11-24-2014
    Location
    Texas
    MS-Off Ver
    Office 2010 and 2007
    Posts
    3,448

    Re: Debug code

    It worked for me....check the spelling of that sheet.
    1N73LL1G3NC3 15 7H3 4B1L17Y 70 4D4P7 70 CH4NG3 - 573PH3N H4WK1NG
    You don't have to add Rep if I have helped you out (but it would be nice), but please mark the thread as SOLVED if your issue is resolved.

    Tom

  3. #3
    Forum Expert gmr4evr1's Avatar
    Join Date
    11-24-2014
    Location
    Texas
    MS-Off Ver
    Office 2010 and 2007
    Posts
    3,448

    Re: Debug code

    OK, I see what happens, after you run it once, it wont work again. Add this just before that line
    Sheets("Finess-Budget").Visible = True
    That sheet was still "very hidden" and needed to be visible.

  4. #4
    Registered User
    Join Date
    10-14-2014
    Location
    USA
    MS-Off Ver
    2010
    Posts
    98

    Re: Debug code

    I don't want it to be visible.
    It should remain hidden.

    Is it possible to only include the name of the second SUB in the first sub?

  5. #5
    Forum Expert gmr4evr1's Avatar
    Join Date
    11-24-2014
    Location
    Texas
    MS-Off Ver
    Office 2010 and 2007
    Posts
    3,448

    Re: Debug code

    It will go back to hidden after it is done.
    Yes, you can call one sub from another. In the first sub code place Call Your Other Sub Name in the line where you want it to run.

  6. #6
    Registered User
    Join Date
    10-14-2014
    Location
    USA
    MS-Off Ver
    2010
    Posts
    98

    Re: Debug code

    The only problem is it is asking me for the password twice.

    I am afraid to delete the sentence asking for the password and if someone enters the wrong password it will still execute the second sub.

    Can you help please?

    Quote Originally Posted by gmr4evr1 View Post
    It will go back to hidden after it is done.
    Yes, you can call one sub from another. In the first sub code place Call Your Other Sub Name in the line where you want it to run.

  7. #7
    Forum Expert gmr4evr1's Avatar
    Join Date
    11-24-2014
    Location
    Texas
    MS-Off Ver
    Office 2010 and 2007
    Posts
    3,448

    Re: Debug code

    It shouldn't ask for the password twice. If someone enters the wrong password, it will exit the sub and not call the second sub. Try this
    Option Explicit
    
    Sub Refresh()
    
    Dim X As Variant
    Dim PW As String
    
    PW = InputBox("Please enter password below", "Password", "")
    
    If PW <> "SALARY" Then
            MsgBox "Incorrect Password"
            Exit Sub
    Else
    
    Application.ScreenUpdating = False
    Sheets("Finess-Actuals").Visible = True
    
    Sheets("Finess-Actuals").Select
    Range("A2:AL290").Select
    
    Sheets("Refresh & Upload").Select
    
    Sheets("Finess-Actuals").Visible = xlSheetVeryHidden
    Application.ScreenUpdating = True
    
    Call secondSub '<----- Your second sub name
    
    MsgBox "Your Budget Refresh is Complete!"
    
    End If
    
    End Sub

  8. #8
    Registered User
    Join Date
    10-14-2014
    Location
    USA
    MS-Off Ver
    2010
    Posts
    98

    Re: Debug code

    In the second sub, there is a line that is exactly the same as the one in the first sub and it starts with "if PW..."

    Should I erase it ?

    Quote Originally Posted by gmr4evr1 View Post
    It shouldn't ask for the password twice. If someone enters the wrong password, it will exit the sub and not call the second sub. Try this
    Option Explicit
    
    Sub Refresh()
    
    Dim X As Variant
    Dim PW As String
    
    PW = InputBox("Please enter password below", "Password", "")
    
    If PW <> "SALARY" Then
            MsgBox "Incorrect Password"
            Exit Sub
    Else
    
    Application.ScreenUpdating = False
    Sheets("Finess-Actuals").Visible = True
    
    Sheets("Finess-Actuals").Select
    Range("A2:AL290").Select
    
    Sheets("Refresh & Upload").Select
    
    Sheets("Finess-Actuals").Visible = xlSheetVeryHidden
    Application.ScreenUpdating = True
    
    Call secondSub '<----- Your second sub name
    
    MsgBox "Your Budget Refresh is Complete!"
    
    End If
    
    End Sub

  9. #9
    Forum Expert gmr4evr1's Avatar
    Join Date
    11-24-2014
    Location
    Texas
    MS-Off Ver
    Office 2010 and 2007
    Posts
    3,448

    Re: Debug code

    Yes, you definitely should. You'll have to delete the End If and Else as well.

  10. #10
    Registered User
    Join Date
    10-14-2014
    Location
    USA
    MS-Off Ver
    2010
    Posts
    98

    Re: Debug code

    Thank you for your help

    Quote Originally Posted by gmr4evr1 View Post
    Yes, you definitely should. You'll have to delete the End If and Else as well.

  11. #11
    Forum Expert gmr4evr1's Avatar
    Join Date
    11-24-2014
    Location
    Texas
    MS-Off Ver
    Office 2010 and 2007
    Posts
    3,448

    Re: Debug code

    No problem, hope it works out for you.

+ 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. Error in the code please debug it
    By kalyaaans in forum Hello..Introduce yourself
    Replies: 1
    Last Post: 09-22-2014, 10:28 AM
  2. VBA Code Runs in Debug Mode But Returns Type Mismatch Error Outside Debug Mode
    By valerie.k.chiang in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 01-24-2014, 03:48 PM
  3. [SOLVED] Debug: How to debug this code?
    By reach78 in forum Excel Programming / VBA / Macros
    Replies: 10
    Last Post: 09-25-2013, 07:16 AM
  4. [SOLVED] VBA Code Debug Error
    By Jennsy in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 12-19-2012, 08:55 AM
  5. Problem trying to debug some code
    By Exadore in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 12-07-2011, 05:28 PM
  6. Debug the Code
    By macrogeek in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 10-17-2011, 06:45 AM
  7. HELP, trying to debug this code...
    By twofootgiant in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 05-18-2011, 12:05 PM

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