Input Box Macro

Wilconcl51

New Member
Joined
Oct 10, 2023
Messages
26
Office Version
  1. 2016
Platform
  1. Windows
My worksheet has named range "Villa". Villa numbers can appear more that once depending on number of residents in each villa with max. of 2.

Trying to create a macro that will
1. Prompt User to input Villa No.
2. If Villa No not found then back to 1. ( That's because Villas are currently numbered 1-270; 401-428; 801-858)
3. Locate the Villa No. and moves one cell to right
4. Prompts User to input either " " or "1"
5. Move one cell to right
6. Prompts User to input either "Y" or ""
7. Loops back to 1. above unless User Exits

Ideally the User should not be able to exit until 7.

Many thanks
 

Excel Facts

Will the fill handle fill 1, 2, 3?
Yes! Type 1 in a cell. Hold down Ctrl while you drag the fill handle.
Maybe something like
VBA Code:
Sub MM1()
Dim Val As Variant
Val = InputBox("Please Insert Villa Number")
Select Case Val
    Case Is <= 270
    Cells(2, 1) = Val
    Case 401 To 428
    Cells(2, 1) = Val
    Case 801 To 858
    Cells(2, 1) = Val
    Case Else
    MsgBox ("incorrect Villa Number, Please start again")
    Exit Sub
End Select
Val = InputBox("Please Leave blank or Enter the number 1")
Cells(2, 2) = Val
Val = InputBox("Please Yes or leave Blank")
Cells(2, 3) = Val
End Sub
 
Upvote 0
Thanks Michael.
The Input Boxes work except that the input data is placed in Row 2 and Not in the row for the Villa I input
Garry
 
Upvote 0
VBA Code:
Sub MM1()
Dim Val As Variant
Val = InputBox("Please Insert Villa Number")
Select Case Val
    Case Is <= 270
    Cells(Val, 1) = Val
    Case 401 To 428
    Cells(Val, 1) = Val
    Case 801 To 858
    Cells(Val, 1) = Val
    Case Else
    MsgBox ("incorrect Villa Number, Please start again")
    Exit Sub
End Select
ans = InputBox("Please Leave blank or Enter the number 1")
Cells(Val, 2) = ans
ans2 = InputBox("Please Yes or leave Blank")
Cells(Val, 3) = ans2
End Sub
 
Upvote 0
VBA Code:
Sub MM1()
Dim Val As Variant
Val = InputBox("Please Insert Villa Number")
Select Case Val
    Case Is <= 270
    Cells(Val, 1) = Val
    Case 401 To 428
    Cells(Val, 1) = Val
    Case 801 To 858
    Cells(Val, 1) = Val
    Case Else
    MsgBox ("incorrect Villa Number, Please start again")
    Exit Sub
End Select
ans = InputBox("Please Leave blank or Enter the number 1")
Cells(Val, 2) = ans
ans2 = InputBox("Please Yes or leave Blank")
Cells(Val, 3) = ans2
End Sub
Hi Michael,

I tested using Villa 199. Data was placed in Row 199 which does not correspond to Villa 199 in my range. It appears the Code is not looking for Villa # in the Range ("Villa")

Garry
 
Upvote 0
UNTESTED
VBA Code:
Sub MM1()
Dim Val As Variant, a As Range
Val = InputBox("Please Insert Villa Number")
With ThisWorkbook.Names("Villa").RefersToRange
    Set c = .Find("Villa " & Val, LookIn:=xlValues)
     If c Is Nothing Then MsgBox "Customer not found"
End With
ans = InputBox("Please Leave blank or Enter the number 1")
Range(c.Address).Offset(, 1) = ans
ans2 = InputBox("Please Yes or leave Blank")
Range(c.Address).Offset(, 2) = ans2
End Sub
 
Upvote 0
UNTESTED
VBA Code:
Sub MM1()
Dim Val As Variant, a As Range
Val = InputBox("Please Insert Villa Number")
With ThisWorkbook.Names("Villa").RefersToRange
    Set c = .Find("Villa " & Val, LookIn:=xlValues)
     If c Is Nothing Then MsgBox "Customer not found"
End With
ans = InputBox("Please Leave blank or Enter the number 1")
Range(c.Address).Offset(, 1) = ans
ans2 = InputBox("Please Yes or leave Blank")
Range(c.Address).Offset(, 2) = ans2
End Sub
Hi Michael,
When I input a known Villa No it comes up with "Customer Not Found. prompts for Next Input
Then stalls at Range(c.Address).Offset(, 1) = ans "object variable or With block variable not set
 
Upvote 0
Can you post a sample of your named range data pls
 
Upvote 0
Can you post a sample of your named range data pls
Weekly meals.xlsm
ABCDEFGHIJK
6
7
8
9Tuesday MealsFriday MealsGluten_Free (Y)VillaNoFirst_NameLast_NameRegulars (Y)Tuesday Cash Tuesday EftposFriday Cash Friday Eftpos
101DesleyCottam
111Maurice Scott
122MargaretRoberts
133CathyThomson
144KathyWeisenberger
155Ray White
165BerylWhite
176PennySteele
186DavidSteele
197LorraineMcPhee
208JohnBeadle
218SueBeadle
229MaureenBrady
2310AnnShaw
2410DennisShaw
2511TedDynes
2611CarolDynes
2712GraceAmbrose
2813ColinDavey
2913CherylDavey
3014IrisSing
3114GraemeSing
3215ValVoyzey
3316RobertHaste
3416FayeHaste
3517RayChurch
3617LarraineChurch
3718ArthurPerry
3818ShirleyPerry
3919SintraWooding
4020TedDwyer
4120SueDwyer
Residents
Cells with Data Validation
CellAllowCriteria
C10:C41Text lengthbetween 0 and 1
 
Upvote 0

Forum statistics

Threads
1,224,828
Messages
6,181,209
Members
453,022
Latest member
RobertV1609

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