• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

VBA code to lookup and fill across

Hi,

Im trying to write a VBA code for lookup few words in a range of cells.

There was no success and end up in recording macro and below mentioned is the code (Using record Macro)

Code:
Sub normallookupstyle()


Selection.FormulaR1C1 = "=VLOOKUP(RC[-1],{123;""23KC"";""Animal"";""Planet"";""Split"";""Layout""},1,0)"
Selection.Copy
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks:=False, Transpose:=False
Application.CutCopyMode = False

End Sub

I have mentioned the un-successful code below (As im not good in VBA coding)

Code:
Sub codingstylelookup()
Dim lookrange() As Variant


lookrange(123,""23KC"",""Animal"",""Planet"",""Split"",""Layout"")


ActiveCell.Value = Application.WorksheetFunction.VLookup(ActiveCell(0, -1).Value, lookrange, 1, 0)


End Sub

Please help me out with a correct VBA code for the code i have highlighted in red color

I would like to fill across the range between B2 to B18 (File attached)

Mr. Excel Question Board link:
http://www.mrexcel.com/forum/excel-q...ll-across.html

Excel Forum link:
http://www.excelforum.com/showthread...14#post4331014
 

Attachments

  • Test file.xlsm
    13.5 KB · Views: 5
Hi:

Try the following code:
Code:
Sub codingstylelookup()

Dim lookrange As Variant
Dim str$
lookrange = Array(123, "23KC", "Animal", "Planet", "Split", "Layout")

For i& = LBound(lookrange) To UBound(lookrange)
    str = Cells(ActiveCell.Row, ActiveCell.Column - 1).Value
    If str = lookrange(i) Then
    ActiveCell.Value = lookrange(i)
    Exit For
    Else
    ActiveCell.Value = "N/A"
    End If
Next

End Sub

Thanks
 
Back
Top