Two Variant with inputbox

Leviathan87

New Member
Joined
Mar 2, 2022
Messages
4
Office Version
  1. 2013
Platform
  1. Windows
I am applying a small part of my code!I have a code with two variable Value1 and Value2 and input box. I want if input number 1 or number 2 the code show me Value1 or if i press number 2 show me Value2

Sub Inputbox()
Dim Name As String
Dim LastRow As Long
Dim Value1 As String
Dim Value2 As String
Value1 = 807063
Value2 = 807059
Name = Application.InputBox("Please Select 1 To 2" & vbLf & vbLf & "1 - 807063 - " & vbLf & "2 - 807059 ", "Enter a value")
If Name = TRUE Then
LastRow = Cells(Rows.Count, "C").End(xlUp).Row + 1
lastRow = lastRow = Cells(Rows.Count, "C").End(xlUp).Row + 1
Range("C" & LastRow).Value = Value1
Else: Value2 = LastRow = Cells(Rows.Count, "C").End(xlUp).Row + 1
lastRow1 = lastRow1 = Cells(Rows.Count, "C").End(xlUp).Row + 1
Range("C" & LastRow).Value = Value2
End If
Exit Sub
 

Excel Facts

Can you AutoAverage in Excel?
There is a drop-down next to the AutoSum symbol. Open the drop-down to choose AVERAGE, COUNT, MAX, or MIN
Try . . .

VBA Code:
Sub Inputbox()

    Dim UserChoice As Variant
    Dim NextRow As Long
    Dim Value1 As String
    Dim Value2 As String
    
    Value1 = 807063
    Value2 = 807059
    
    Do
        UserChoice = Application.Inputbox("Please Select 1 To 2" & vbLf & vbLf & "1 - 807063 - " & vbLf & "2 - 807059 ", "Enter a value", Type:=1)
        If UserChoice = False Then Exit Sub
        If UserChoice = 1 Or UserChoice = 2 Then Exit Do
        MsgBox "Number is invalid.", vbExclamation
    Loop
    
    NextRow = Cells(Rows.Count, "C").End(xlUp).Row + 1
    
    If UserChoice = 1 Then
        Range("C" & NextRow).Value = Value1
    ElseIf UserChoice = 2 Then
        Range("C" & NextRow).Value = Value2
    End If
    
End Sub

Hope this helps!
 
Upvote 0
Solution
One other thing:

You should NEVER use reserved words like "Inputbox" as the name of your procedures, functions, or variables!
Doing so can cause errors and unexpected results (when you try to call "Inputbox", Excel may have trouble figuring out whether you mean your procedure or the built-in InputBox).
 
Upvote 0

Forum statistics

Threads
1,215,059
Messages
6,122,913
Members
449,093
Latest member
dbomb1414

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