Macro If And issue

fastballfreddy

Board Regular
Joined
Jan 13, 2015
Messages
57
Office Version
  1. 2016
Platform
  1. Windows
Trying to add an And to the if statement below (red font) and keeps coming back to wrong# (I type in 1 and cell E1 = 1 so it should type Dice 1 into cell A1). I'm sure it's an easy fix but can't figure out what is wrong with my macro. Thanks in advance for reviewing

Sub Test2()

Dim InputText1 As String

InputText1 = InputBox("Enter #")


If StrPtr(InputText1) = 1 And Range("E1").Value = "1" Then
Range("A1").Select
ActiveCell.FormulaR1C1 = "DICE 1"
ElseIf InputText1 = 2 Then
Range("A1").Select
ActiveCell.FormulaR1C1 = "DICE 2"
ElseIf InputText1 = 3 Then
Range("A1").Select
ActiveCell.FormulaR1C1 = "DICE 3"
ElseIf InputText1 = 4 Then
Range("A1").Select
ActiveCell.FormulaR1C1 = "DICE 4"
Else
MsgBox "Wrong #"
End If

End Sub
 

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.
Hi,

Please check with below...
I have removed double quotes..

VBA Code:
If StrPtr(InputText1) = 1 And Range("E1").Value = 1 Then
 
Upvote 0
How about
VBA Code:
Sub Test2()

Dim InputText1 As String

InputText1 = InputBox("Enter #")

If InputText1 = "1" And Range("E1").Value = 1 Then
   Range("A1").Value = "DICE 1"
ElseIf InputText1 = "2" Then
   Range("A1").Value = "DICE 2"
ElseIf InputText1 = "3" Then
   Range("A1").Value = "DICE 3"
ElseIf InputText1 = "4" Then
r ange("A1").Value = "DICE 4"
Else
   MsgBox "Wrong #"
End If

End Sub
 
Upvote 0
Solution
Glad we could help & thanks for the feedback.
 
Upvote 0

Forum statistics

Threads
1,214,581
Messages
6,120,372
Members
448,957
Latest member
BatCoder

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