Most effective way to insert vlookup formula?

srosk

Board Regular
Joined
Sep 17, 2018
Messages
132
I have a spreadsheet that I will be manually adding data to columns C:K. Periodically, I would like to run a macro that searches for rows where column C has a value, but column B is blank for that row. If column B is blank:

insert a separate formula in column A and column B for that specific row

Is this possible with VBA?
 
I am not so sure I understand, so pardon my ignorance. If column C contains a value in any row (value could be any alphanumeric value)... then if column A is blank, insert column A formula for that row... and if column B is blank, insert column B formula for that row that was checked in column C.

Is this any bit helpful?

Thanks for all that you do!

Or try this:

Code:
Sub test_formula()
    Dim c As Range, lr As Long
    lr = Range("C" & Rows.Count).End(xlUp).Row
    For Each c In Range("B5:B" & lr).SpecialCells(xlCellTypeBlanks)
        If c.Offset(0, 1) <> "" Then
            c.FormulaR1C1 = "=VLOOKUP(RC[1],'A B'!C:C[2],3,0)"
        End If
    Next
    For Each c In Range("A5:A" & lr).SpecialCells(xlCellTypeBlanks)
        If c.Offset(0, 2) <> "" Then
            c.FormulaR1C1 = "=VLOOKUP(RC[2],'A B'!C[1]:C[3],2,0)"
        End If
    Next
End Sub
 
Upvote 0

Excel Facts

What is =ROMAN(40) in Excel?
The Roman numeral for 40 is XL. Bill "MrExcel" Jelen's 40th book was called MrExcel XL.
Please see DanteAmor's post number 11 and not mine as he spotted that you have the condition if column C isn't blank which I missed (although personally I would cater for that in the formula and return a "")
 
Last edited:
Upvote 0

Forum statistics

Threads
1,215,106
Messages
6,123,124
Members
449,096
Latest member
provoking

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