Help with Indexing in VBA

shiva_reshs

Board Regular
Joined
Sep 5, 2012
Messages
68
Hello,

I am not able to figure out, what is wrong in this Indexing code.

Code:
<code>Range("R6").Select ActiveCell.FormulaR1C1 = "=IF($Q6="","",INDEX('Worker-Exempt'!B:B,MATCH($Q6,'Worker-Exempt'!A:A,0)))"</code></pre>

I get application 1004 error msg.

Cross Posting

HTML:
http://www.excelforum.com/excel-programming-vba-macros/960412-vlookup-to-index-matching-in-vba.html
 

Excel Facts

Who is Mr Spreadsheet?
Author John Walkenbach was Mr Spreadsheet until his retirement in June 2019.
Try

Code:
Range("R6").Formula = "=IF($Q6="""","""",INDEX('Worker-Exempt'!B:B,MATCH($Q6,'Worker-Exempt'!A:A,0)))"
 
Upvote 0
Thanks VoG,

It works. But one small issue here.

I am dragging the code till below.

Code:
Application.CutCopyMode = False
    Selection.Copy
    ActiveCell.Offset(0, -1).Select
    Selection.End(xlDown).Select
    ActiveCell.Offset(0, 1).Select
    Range(Selection, Selection.End(xlUp)).Select
    ActiveSheet.Paste
    Selection.Copy
    Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
        :=False, Transpose:=False

If I specify to R6 cell, then how can I drag it to bottom??

Thanks
 
Upvote 0
Try like this

Code:
LR = Range("Q" & Rows.Count).End(xlUp).Row
Range("R6:R" & LR).Formula = "=IF($Q6="""","""",INDEX('Worker-Exempt'!B:B,MATCH($Q6,'Worker-Exempt'!A:A,0)))"
 
Upvote 0
Hi,

Sorry being naive on this: )
I need to copy the data and paste values, so can get rid of the underlying formula. Please advise.

I tried below workaround but it failed.


Code:
Lr1 = Range("M" & Rows.Count).End(xlUp).Row
Range("N6:N" & Lr1).Formula = "=IF($L6="""","""",INDEX('US Exempt Worker- US Exempt Wor'!C:C,MATCH($L6,'US Exempt Worker- US Exempt Wor'!B:B,0)))"
    lr2 = Range("N" & Rows.Count).End(xlUp).Row
   [COLOR=#ff0000] Range(lr2).Select[/COLOR]  ''' I know it is wrong, but trying best i could..
    Selection.Copy
    Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
        :=False, Transpose:=False
 
Upvote 0
Try

Code:
With Range("N6:N" & Lr1)
    .Formula = "=IF($L6="""","""",INDEX('US Exempt Worker- US Exempt Wor'!C:C,MATCH($L6,'US Exempt Worker- US Exempt Wor'!B:B,0)))"
    .Value = .Value
End With
 
Upvote 0
Hello,

I need another tweak the formula above. When Cell value is returned to #N/A, cell displayes #N/A. Can I change it to "-" sign?
I know replace all formula, just wondering if tweak in the code can do this or not?

Thanks
 
Upvote 0
Maybe (untested)

Code:
With Range("N6:N" & lr1)
    .Formula = "=IF($L6="""","""",INDEX('US Exempt Worker- US Exempt Wor'!C:C,MATCH($L6,'US Exempt Worker- US Exempt Wor'!B:B,0)))"
    .Value = .Value
End With
For i = 6 To lr1
    If Range("N" & i).Text = "#N/A" Then .Value = "-"
Next i
 
Upvote 0

Forum statistics

Threads
1,214,827
Messages
6,121,809
Members
449,048
Latest member
greyangel23

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