Vba to find a Cell from Input Box the move 3 colums to the left

Wilconcl51

New Member
Joined
Oct 10, 2023
Messages
26
Office Version
  1. 2016
Platform
  1. Windows
I am new to Excel and this is doing my head in

I have Named Range of 500 Villas. I seek to move to cell where user inputs Villa Number, then move three colums to the left.

Much appreciated
 

Excel Facts

How to fill five years of quarters?
Type 1Q-2023 in a cell. Grab the fill handle and drag down or right. After 4Q-2023, Excel will jump to 1Q-2024. Dash can be any character.
I am new to Excel and this is doing my head in

I have Named Range of 500 Villas. I seek to move to cell where user inputs Villa Number, then move three colums to the left.

Much appreciated
So, you have 500 named ranges on the same workbook, correct?
So, if you have a named Range of "Alpha" and you enter "Alpha" in Input box you want the active cell to now be 3 cells to the right of that named range. Is this correct?
 
Upvote 0
So, you have 500 named ranges on the same workbook, correct?
So, if you have a named Range of "Alpha" and you enter "Alpha" in Input box you want the active cell to now be 3 cells to the right of that named range. Is this correct?
Named Range is "Villa" Range D2:D520 Worksheet is "Residents"
Need User from an Input Box find specific Villa say "189" then go the cell 3 columns to the left.
 
Upvote 0
You said:
Range D2:D520 Worksheet is "Residents"

So, you want to search the Range D2:D520 in sheet named "Residents"
For the value you enter into InputBox Is that correct?
 
Upvote 0
You said:
Range D2:D520 Worksheet is "Residents"

So, you want to search the Range D2:D520 in sheet named "Residents"
For the value you enter into InputBox Is that correct?
Yes. Then go to that cell and then move 3 columns to the left.
 
Upvote 0
Give this a try.
I have assumed that the named range "Villa" has 'Workbook' scope.

VBA Code:
Sub Test()
  Dim rVilla As Range
  Dim Resp As String
 
  Resp = InputBox("What Villa?")
  On Error Resume Next
  Set rVilla = Range("Villa").Find(What:=Resp, LookAt:=xlWhole)
  On Error GoTo 0
  If rVilla Is Nothing Then
    MsgBox "Villa " & Resp & " not found"
  Else
    Application.Goto Reference:=rVilla.Offset(, -3), Scroll:=True
  End If
End Sub
 
Upvote 0
Give this a try.
I have assumed that the named range "Villa" has 'Workbook' scope.

VBA Code:
Sub Test()
  Dim rVilla As Range
  Dim Resp As String
 
  Resp = InputBox("What Villa?")
  On Error Resume Next
  Set rVilla = Range("Villa").Find(What:=Resp, LookAt:=xlWhole)
  On Error GoTo 0
  If rVilla Is Nothing Then
    MsgBox "Villa " & Resp & " not found"
  Else
    Application.Goto Reference:=rVilla.Offset(, -3), Scroll:=True
  End If
End Sub
That is excellent. Thank you so much
 
Upvote 0
That is excellent. Thank you so much
My code is as follows and works well except when user hits cancel button or ok without inputting data

How do I fix this

Garry
VBA Code:
Sub Macro7()

  Dim rVilla As Range
  Dim Resp As String
 
  Resp = InputBox("What is their Villa Number.  Villa Number only?. Ctrl+ Shift+ A to start over")
  On Error Resume Next
  Set rVilla = Range("Villa").Find(What:=Resp, LookAt:=xlWhole)
 On Error GoTo 0
   If rVilla Is Nothing Then
    MsgBox "Villa " & Resp & " not found"
    'End If
  Else
    Application.Goto Reference:=rVilla.Offset(, -3), Scroll:=True
 End If

End Sub
 
Last edited by a moderator:
Upvote 0

Forum statistics

Threads
1,223,911
Messages
6,175,326
Members
452,635
Latest member
laura12345

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