Hi,
Can anybody see my fault here? I am trying to add a vlookup formula to a cell (t)
t.Offset(0, 2).Value = Application.VLookup(t.Value, Admin!$A$2:$B$19, 2, False)
Thanks
![]() |
Patch reliability is unclear. Unless you have an immediate, pressing need to install a specific patch, don't do it. |
SIGN IN | Not a member? | REGISTER | PLUS MEMBERSHIP |
Home » Forums » AskWoody support » Productivity software by function » MS Excel and spreadsheet help » Add formula to cell (vba)
It would look something like this -assuming that your q was explicitly designated.
t.Offset(0, 2).Formula = “=VLookup(” & t.Offset(0, -1).Value & “,Admin!$A$2:$B$19, 2, 0)”
Thanks Mike, a few hours kip was required after spending far too long trying to sort this. Thankfully Rory has provided a working solution. I appreciate all of your help!
Code:t.Offset(0, 2).FormulaR1C1 = "=VLookup(RC[-3],Admin!R2C1:R19C2,2,0)"
t.Offset(0, 2).FormulaR1C1 = “=VLookup(RC[-3],Admin!R2C1:R19C2,2,0)”
Thanks Rory, that does work as I require. However, is it possible to set a reference to Admin!R2C1:R19C2 and then use that in the formula? The reason that I ask is that I need to use this several times over, so would be easier for future maintenance.
Thanks Rory, perfect.
I’m having a mare of a time trying to create these formulas ‘on the fly’. Could I please trouble you for some further help.
t = range (one cell)
x = range (range of cells)
w = long (last row number)
What I am attempting to do is: for each cell in a range of cells, add formula’s to 3 columns that would look like the following (based on row 5) in the actual formula’s
For Each t In x 't.Offset(0, 12).Formula = "=S5-Z5" 't.Offset(0, 13).Formula = "=RANK(S5,S5:S & w)" 't.Offset(0, 15).Formula = "=SUMPRODUCT((B5=B5:B & w)*(S5<S5:S & w))+1" Next t
Thanks
So column H then.
Try this:
For Each t In x t.Offset(0, 12).FormulaR1C1 = "=RC[-1]-RC[6]" t.Offset(0, 13).Formula = "=RANK(RC[-2],R5C[-2]:R" & w & "C[-2])" t.Offset(0, 15).Formula = "=SUMPRODUCT((RC[-21]=R5C[-21]:R" & w & "C[-21])*(RC[-4]<R5C[-4]:R" & w & "C[-4]))+1" Next t
I've taken a guess that you wanted the rows 5:w bits to be fixed – i.e. the same for each row the formula is entered into.
Donations from Plus members keep this site going. You can identify the people who support AskWoody by the Plus badge on their avatars.
AskWoody Plus members not only get access to all of the contents of this site -- including Susan Bradley's frequently updated Patch Watch listing -- they also receive weekly AskWoody Plus Newsletters (formerly Windows Secrets Newsletter) and AskWoody Plus Alerts, emails when there are important breaking developments.
Welcome to our unique respite from the madness.
It's easy to post questions about Windows 11, Windows 10, Win8.1, Win7, Surface, Office, or browse through our Forums. Post anonymously or register for greater privileges. Keep it civil, please: Decorous Lounge rules strictly enforced. Questions? Contact Customer Support.
Want to Advertise in the free newsletter? How about a gift subscription in honor of a birthday? Send an email to sb@askwoody.com to ask how.
Mastodon profile for DefConPatch
Mastodon profile for AskWoody
Home • About • FAQ • Posts & Privacy • Forums • My Account
Register • Free Newsletter • Plus Membership • Gift Certificates • MS-DEFCON Alerts
Copyright ©2004-2025 by AskWoody Tech LLC. All Rights Reserved.
Notifications