VLookup in VBA

mgw1138

New Member
Joined
Mar 9, 2014
Messages
33
I keep getting "unable to get vlookup property of the WorksheetFunction class"
The table is 4 columns: id number, description, Width, Height
The sheet has 24 rectanges I want to make each active and then call the macro and input rectange number.
I was going to get more sophisticated with an external loop but I can not get a single retangle to modify.

Thanks in advance


Dim DoBox As Integer
Dim WorkRec As String

DoBox = InputBox("What Rec")
WorkRec = "Rectangle " & DoBox

With ActiveSheet.Shapes.Range(Array(WorkRec))
.Width = Application.WorksheetFunction.VLookup(DoBox, "o2:r24", 3)
.Height = Application.WorksheetFunction.VLookup(DoBox, "o2:r24", 4)
.Text = Application.WorksheetFunction.VLookup(DoBox, "o2:r24", 2)
End With
 

Excel Facts

Repeat Last Command
Pressing F4 adds dollar signs when editing a formula. When not editing, F4 repeats last command.
I would use Range's Find rather than =vlookup. vlookup requires that the data be sorted.

Besides the range issue in vlookup, you need the line before End With to set the Text property.
VBA Code:
Sub Main()
  Dim DoBox As Integer, WorkRec As String, s As Shape
  
  DoBox = InputBox("What Rec")
  WorkRec = "Rectangle " & DoBox
  'On Error GoTo EndNow
  Set s = Sheet1.Shapes(WorkRec)
  'ActiveSheet.Shapes.Range (Array(WorkRec))
  With s
    .Width = Application.WorksheetFunction.VLookup(DoBox, [o2:r24], 3)
    .Height = Application.WorksheetFunction.VLookup(DoBox, [o2:r24], 4)
    .TextFrame.Characters.Text = Application.WorksheetFunction.VLookup(DoBox, [o2:r24], 2)
  End With
  
EndNow:
End Sub
 
Upvote 0

Forum statistics

Threads
1,214,649
Messages
6,120,733
Members
448,987
Latest member
marion_davis

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