You are here:

Excel/macro within a formula

Advertisement


Question
Tom

I found a function code that works fine, but i cant seem to get it to close the customer page and open the code page ...the following is the test maco

Sub entermasterpswd2()
   Dim x
    
   x = InputBoxDK("Type your password here.", "Password Required")
   If x = "" Then End
   
   If x <> Sheet19.Range("D1").Value Then
       MsgBox "You didn't enter a correct password."
       End
   End If
       
   Application.ScreenUpdating = False
    
         With Worksheets("Code")
         .Visible = xlSheetVisible
         .Activate
         .Range("D3").Select
         
    .Range("II6").Select
         
   Sheets("Customer").Select
   ActiveWindow.SelectedSheets.Visible = False
         
   ActiveWindow.DisplayHeadings = False
         
       End With
   
   Application.ScreenUpdating = True
   'MsgBox "Successful", vbExclamation
    
End Sub

if i activate the successful msgbox and take out whats above it to the end if it works fine i enter the correct password and it displays the msgbox, but when i place what i want it to do and trigger it like the above code it takes the password then does nothing....

ideas?

Tony

Answer

x = InputBoxDK("Type your password here.", "Password Required")
  If x = "" Then End
  
  If x <> Sheet19.Range("D1").Value Then
      MsgBox "You didn't enter a correct password."
      End
  End If

so I have no idea what InputBoxDK returns.  But right after the inputboxDK is executed, if it returns a null string, the procedure Ends   note that I never use the End Command as it totally resets the environment and halts all code.

in you next line, you are comparing toe Sheet19.Range("D1"). if x doesn't match the value stored there, then again, you execute and END command.  (in your previous post, you were looking at  Sheet271.Range("W1")  

I really don't understand you terminology in your question but I provided what analysis I could perform.

--
Regards,
Tom Ogilvy

About Excel
This topic answers questions related to Microsoft Excel spreadsheet (or workbook) stand-alone or Mircrosoft Office Excel including Excel 2003, Excel 2007, Office 2000, and Office XP. You can get Excel help on Excel formulas(or functions), Excell macros, charting in Excel, advanced features, and the general use of Excel. This does not provide a general Excel tutorial nor the basics of using a spreadsheet. It provides specific answers to using Microsoft Excel only. If you do not see your Excel question answered in this area then please ask an Excel question here

Excel

All Answers


Answers by Expert:


Ask Experts

Volunteer


Tom Ogilvy

Expertise

Selected as an Excel MVP by Microsoft since 1999. Answering Excel questions in Allexperts since its inception in 2001. Able to answer questions on almost all aspects of Excel's internal capabilities. If seeking a VBA solution, please specify that in your question itself so I give you the answer you want. [Excel has weak protection - if you are distributing an application, I don't answer questions on how to protect your project from your users.]

Experience

Extensive experience.

Education/Credentials
Master of Science (MS) degree Operations Research (ORSA)

Awards and Honors
Microsoft MVP in Excel.

©2016 About.com. All rights reserved.