Hi,
I'm relatively new to VBA and having issues when using Vlookup. I'm looking to create a input box where users enter a location and it returns the address of a particular store. The workbook contains information over 12 different sheets and I want it to look through each sheet and if it doesn't find the information on the first, it moves to the next and so on.
I have used this to test against one of the sheets and it works fine:
Sub BranchAddress()
On Error GoTo MyErrorHandler:
Dim Branch_Name As String
Branch_Name = InputBox("Enter the Branch Name : ")
If Len(Branch_Name) > 0 Then
Address = Application.WorksheetFunction.VLookup(Branch_Name, Sheets("Area1").Range("C7:D42"), 2, False)
MsgBox "Branch address is : " & Address
End If
Else
MsgBox ("You have entered an incorrect branch")
End If
Exit Sub
MyErrorHandler:
If Err.Number = 1004 Then
MsgBox "Branch address is not available"
End If
End Sub
But I cannot think how to get this to work across multiple sheets?
Any help would be great!
I'm relatively new to VBA and having issues when using Vlookup. I'm looking to create a input box where users enter a location and it returns the address of a particular store. The workbook contains information over 12 different sheets and I want it to look through each sheet and if it doesn't find the information on the first, it moves to the next and so on.
I have used this to test against one of the sheets and it works fine:
Sub BranchAddress()
On Error GoTo MyErrorHandler:
Dim Branch_Name As String
Branch_Name = InputBox("Enter the Branch Name : ")
If Len(Branch_Name) > 0 Then
Address = Application.WorksheetFunction.VLookup(Branch_Name, Sheets("Area1").Range("C7:D42"), 2, False)
MsgBox "Branch address is : " & Address
End If
Else
MsgBox ("You have entered an incorrect branch")
End If
Exit Sub
MyErrorHandler:
If Err.Number = 1004 Then
MsgBox "Branch address is not available"
End If
End Sub
But I cannot think how to get this to work across multiple sheets?
Any help would be great!