VBA Error: Invalid Use of Property

HeyItsTyler

New Member
Joined
Dec 12, 2018
Messages
3
I'm working on constructing a macro that will look up information for a studio based on the studio identifier that is inputted. I am trying to set it up with error messages for the user that if the studio number is not found in the lookup area, it will return an error saying so and an additional error if the field is left blank. I am receiving an error that there is an Invalid Use of Property, highlighting in yellow the first line, "Sub studioinfolookup()". I'm very new to VBA so any direction and help would be greatly appreciated.



Code:
Sub studioinfolookup()    
Dim studionumber As String
Dim address As String
Dim city As String
Dim state As String
Dim zip As Integer


studionumber = Range("C2")


Set addressrange = Range("L:M")
Set cityrange = Range("L:N")
Set staterange = Range("L:O")
Set ziprange = Range("L:P")


address = Application.WorksheetFunction.VLookup(studionumber, addressrange, 2, False)
city = Application.WorksheetFunction.VLookup(studionumber, cityrange, 3, False)
state = Application.WorksheetFunction.VLookup(studionumber, staterange, 4, False)
zip = Application.WorksheetFunction.VLookup(studionumber, ziprange, 5, False)
On Error GoTo myerrorhandler:


If Len(studionumber) > 0 Then
    
Set Range("B4:B7") = Nothing
Set Range("B4") = address
Set Range("B5") = city
Set Range("B6") = state
Set Range("B7") = zip


Else
    MsgBox "No Studio Number Entered!"


End If


Exit Sub


myerrorhandler:
If Err.Number = 1004 Then
MsgBox "Studio Number not found. Please enter as (Country Code)(Store Identifier Number). Ex: CAN100 or US001"
End If
 

Excel Facts

Round to nearest half hour?
Use =MROUND(A2,"0:30") to round to nearest half hour. Use =CEILING(A2,"0:30") to round to next half hour.
Hi & welcome to MrExcel
Try
Code:
If Len(studionumber) > 0 Then
    
 Range("B4:B7") = ""
 Range("B4") = address
 Range("B5") = city
 Range("B6") = state
 Range("B7") = zip


Else
    MsgBox "No Studio Number Entered!"


End If
 
Upvote 0
You're welcome & thanks for the feedback
 
Upvote 0

Forum statistics

Threads
1,214,915
Messages
6,122,212
Members
449,074
Latest member
cancansova

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