VBA Code to Lookup value in range & update cell in row

Patchworks

New Member
Joined
Jul 15, 2009
Messages
23
I have a function that is called upon saving a UserForm. One of the Text Labels contains the ID field that I need to use to do a lookup into the first column of a Named Range and then I need to update the cell in the 4th column of that row.

From my research, I'm assuming it will go something like this:

Code:
Application.WorksheetFunction.VLookup(valve, Worksheets("TestWorksheet").Range("TestRange".Cells), 10, False).Value = "TestValue"
Can someone help me out?
 
Actually for Match and Vlookup you should change it to

APPLICATION.match and APPLICATION.vlookup.

you're probably getting the error because the match/vlookup failed to find the key. If "Forums" is a named range, you don't need the Quotes around it..

Code:
Cells(WorksheetFunction.Match(frmForumsPosting.ForumID.Caption, Forums, 0), 10) = "On Hold"
You'll probably want to evaluate the expression prior to executing it to determine if it's going to be valid, unless you're confident a match will always be found..

eg Iserror(expression)

phxsportz,

Yes, "Forums" is a named range! Unfortunately, I'm not very good with VBA. Would you mind showing me an example of the code your are referring to?

Thanks so much for you patience and help.

g
 
Upvote 0

Excel Facts

How can you automate Excel?
Press Alt+F11 from Windows Excel to open the Visual Basic for Applications (VBA) editor.
Ok.. what is the Range that is assigned to Forums ? It must be a column or a row, but it can't be multidimensional for use with MATCH(). It will always return "N/A#" if it's multidimensional eg (A1:B10)

Cells(application.Match(frmForumsPosting.ForumID.Caption, Forums, 0), 10) = "On Hold"
 
Upvote 0

Forum statistics

Threads
1,216,222
Messages
6,129,589
Members
449,520
Latest member
TBFrieds

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