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

Difference between two dates
Secret function! Use =DATEDIF(A2,B2,"Y")&" years"&=DATEDIF(A2,B2,"YM")&" months"&=DATEDIF(A2,B2,"MD")&" days"
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,223,903
Messages
6,175,284
Members
452,630
Latest member
OdubiYouth

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