[Ask-VBA] input box with fixed input

eddorena

New Member
Joined
Dec 3, 2021
Messages
47
Office Version
  1. 365
Platform
  1. Windows
Hi All,

In another thread I discussed about auto insert and get support from @HaHoBe and now I tried to make the input box only can fill by fix four values (DM, DT, DS and DW) and each value was set the amount such DM is 4, DS is 4, DT is 5 and DW is 8.

I tried using If fiction, and I don't know why not working, whether any one can help me

Plan to modify by adding "line" and change "lngNrRows" with line

VBA Code:
 Dim lngRow As Long

  Dim lngNrRows As Long
 
  Dim line As Long

 

  lngNrRows = InputBox(Prompt:="Fill number line to insert")
 
  If lngNrRows = "DW" Then line = 4
    ElseIf lngNrRows = "DS" Then line = 4
    ElseIf lngNrRows = "DT" Then line = 5
    ElseIf lngNrRows = "Dw" Then line = 8
  End If

This is the Original

VBA Code:
Private Sub Click_Click()
'On Error Resume Next
  Dim lngRow As Long
  Dim lngNrRows As Long
 
  lngNrRows = InputBox(Prompt:="Fill number line to insert")
  lngRow = InputBox(Prompt:="Fill number line to insert")

  With ThisWorkbook.Sheets("Sheet2")
    .Cells(lngRow - 1, "A").Resize(1, 8).Copy
    .Cells(lngRow, "A").Resize(lngNrRows, 8).Insert Shift:=xlDown
  End With
  With ThisWorkbook.Sheets("Sheet1")
    .Cells(lngRow - 1, "A").Resize(1, 8).Copy
    .Cells(lngRow, "A").Resize(lngNrRows, 8).Insert Shift:=xlDown
  End With
End Sub


Thank You
 

Excel Facts

Return population for a City
If you have a list of cities in A2:A100, use Data, Geography. Then =A2.Population and copy down.
Hi,
see if this update to your first code will do what you want

VBA Code:
    Dim Entry            As Variant, arr As Variant, m As Variant
    Dim line               As Long
   
    arr = Array("DM", "DS", "DT", "DW")
   
    Do
        Entry = InputBox(Prompt:="Fill number line To insert")
        'cancel pressed
        If StrPtr(Entry) = 0 Then Exit Sub
        m = Application.Match(Entry, arr, 0)
    Loop Until Not IsError(m)
   
    line = Choose(m, 4, 4, 5, 8)

Dave
 
Upvote 1
Solution
Hi,
see if this update to your first code will do what you want

VBA Code:
    Dim Entry            As Variant, arr As Variant, m As Variant
    Dim line               As Long
  
    arr = Array("DM", "DS", "DT", "DW")
  
    Do
        Entry = InputBox(Prompt:="Fill number line To insert")
        'cancel pressed
        If StrPtr(Entry) = 0 Then Exit Sub
        m = Application.Match(Entry, arr, 0)
    Loop Until Not IsError(m)
  
    line = Choose(m, 4, 4, 5, 8)

Dave

Hi Dave @dmt32

Tested and 100% works (y) (y) (y) (y) (y) , Thank You :coffee:
I'll learn and explore in future to use array process.

I marked as solve answer.🤓
 
Upvote 0
Hi
Glad suggestion resolves the issue & appreciate your feedback

Dave
 
Upvote 1

Forum statistics

Threads
1,224,824
Messages
6,181,187
Members
453,020
Latest member
Mohamed Magdi Tawfiq Emam

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