User input for IF statement

nitrammada

Board Regular
Joined
Oct 10, 2018
Messages
78
Office Version
  1. 365
Platform
  1. Windows
Hi Everyone,
I want an input box to pop up in a VBA If statement asking for a code that should match what is in cell B2 as one of the conditions within the if statement.
This is what I have so far from trial and error and from gleaning what I can from MrExcel forums, but I'm stuck.

VBA Code:
Sub UpdateTestL1()

Application.ScreenUpdating = False
Application.EnableEvents = False
ActiveSheet.Unprotect
Application.Calculation = xlCalculationManual
Dim ws As Worksheet, MyRng As Range
Dim lWS_Visible_State As Long
Dim aaa As String

    'aaa = Application.InputBox("Enter function for cell B2.")
    
        Set MyRng = Application.InputBox(Prompt:="Enter function for cell B2.")

        If ws.Range("A1") = "L1" And ws.Range("B2") = MyRng Then
            ws.Range("D6") = "1500000"

        End If
           
Application.Calculation = xlCalculationAutomatic
Application.ScreenUpdating = True
Application.EnableEvents = True

End Sub

Can anyone help? Any suggestions appreciated.
Regard
Adam
 

Excel Facts

Links? Where??
If Excel says you have links but you can't find them, go to Formulas, Name Manager. Look for old links to dead workbooks & delete.
What sheet is "ws"?
Try to set it to, i.e, sheet1

set ws = worksheets("Sheet1")

also

If ws.Range("A1").value = "L1" And ws.Range("B2").value= MyRng Then
ws.Range("D6").value = "1500000"

Does it work?
 
Upvote 0
Hi bebo,
Thanks for your prompt reply. ws is a range of sheets within the workbook. I have 100's of very hidden sheets all will different names, that why I have an if statement with 2 criteria to select only the sheet that has say "NTV#15" in cell B2. I need an input box to pop up and prompt the user to insert "NTV#15". This will then only select the one sheet that meets that criteria and populate cell D6 with the value of "1500000". I hope that makes sense.

I tried placing ".Value" after the cell reference as you had shown in red, but unfortunately that did not work. Thanks so much for your suggestion.
 
Upvote 0

Forum statistics

Threads
1,215,487
Messages
6,125,073
Members
449,205
Latest member
Healthydogs

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top