index/match dynamic range

MiGon

New Member
Joined
Oct 27, 2020
Messages
28
Office Version
  1. 2013
Platform
  1. Windows
Hi all,
I have coded my index match but I used formula instead of function, also my code has set ranges instead of dynamic ones.
Clumns A,C,F changes everyday so need to implement index/match functions and dynamic ranges. Is there a chance someone could kindly help me with this, please.
Thank you
Michal

VBA Code:
*****Static Code*****
'index match
  
    Range("B4").Select
    ActiveCell.FormulaR1C1 = "=INDEX(C[4],MATCH(RC[-1],C[1],0))"
    Range("B4").Select
    LRow = Range("B4").End(xlDown).Row
    Selection.AutoFill Destination:=Range("B4:B" & LRow)
    Range("B4:B" & LRow).Select
    Columns("B:B").Select
    Selection.copy
    Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
        :=False, Transpose:=False
    Application.CutCopyMode = False
    Selection.Replace What:="#N/A", Replacement:="-", LookAt:=xlPart, _
        SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
        ReplaceFormat:=False
  
    With Selection
        .HorizontalAlignment = xlCenter
        .VerticalAlignment = xlBottom
        .WrapText = False
        .Orientation = 0
        .AddIndent = False
        .IndentLevel = 0
        .ShrinkToFit = False
        .ReadingOrder = xlContext
        .MergeCells = False
    End With
 

Attachments

  • Capture.PNG
    Capture.PNG
    14.3 KB · Views: 12
Last edited by a moderator:

Excel Facts

What does custom number format of ;;; mean?
Three semi-colons will hide the value in the cell. Although most people use white font instead.
Hi & welcome to MrExcel.
How about
VBA Code:
Sub MiGon()
   With Range("B4:B", Range("A" & Rows.Count).End(xlUp).Row)
      .FormulaR1C1 = "=INDEX(C[4],MATCH(RC[-1],C[1],0))"
      .Value = .Value
      .Replace "#N/A", "-", xlPart, , , , False, False
      .HorizontalAlignment = xlCenter
      .VerticalAlignment = xlBottom
      .WrapText = False
   End With
End Sub
 
Upvote 0
Hi & welcome to MrExcel.
How about
VBA Code:
Sub MiGon()
   With Range("B4:B", Range("A" & Rows.Count).End(xlUp).Row)
      .FormulaR1C1 = "=INDEX(C[4],MATCH(RC[-1],C[1],0))"
      .Value = .Value
      .Replace "#N/A", "-", xlPart, , , , False, False
      .HorizontalAlignment = xlCenter
      .VerticalAlignment = xlBottom
      .WrapText = False
   End With
End Sub
Hi,
thank you for the quick response but getting 'Run-time error 1004', Method Range of object _Global failed
 

Attachments

  • Capture1.PNG
    Capture1.PNG
    2.4 KB · Views: 4
Upvote 0
Oops, it should be
VBA Code:
Sub MiGon()
   With Range("B4:B" & Range("A" & Rows.Count).End(xlUp).Row)
      .FormulaR1C1 = "=INDEX(C[4],MATCH(RC[-1],C[1],0))"
      .Value = .Value
      .Replace "#N/A", "-", xlPart, , , , False, False
      .HorizontalAlignment = xlCenter
      .VerticalAlignment = xlBottom
      .WrapText = False
   End With
End Sub
 
Upvote 0
Oops, it should be
VBA Code:
Sub MiGon()
   With Range("B4:B" & Range("A" & Rows.Count).End(xlUp).Row)
      .FormulaR1C1 = "=INDEX(C[4],MATCH(RC[-1],C[1],0))"
      .Value = .Value
      .Replace "#N/A", "-", xlPart, , , , False, False
      .HorizontalAlignment = xlCenter
      .VerticalAlignment = xlBottom
      .WrapText = False
   End With
End Sub
Thanks Very much!
 
Upvote 0
You're welcome & thanks for the feedback.
 
Upvote 0

Forum statistics

Threads
1,214,932
Messages
6,122,332
Members
449,077
Latest member
jmsotelo

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