Index Match in VBA

effka

New Member
Joined
Mar 31, 2022
Messages
20
Office Version
  1. 2021
Platform
  1. Windows
Hello,

I'm trying to rearrange data with macro code something like below:
1707337746362.png


For this matter, I wrote a macro code:
VBA Code:
Sub Sample()
    Dim ws As Worksheet
    Dim LastRow4 As Long
    Dim LastRow5 As Long
    Dim LastRow6 As Long
    Dim LastRow7 As Long
    Dim LastColumn As Long
    Dim col As Long
    Dim row As Long

    With ws
       
        LastRow4 = .Range("F" & .Rows.Count).End(xlUp).row
        LastRow5 = .Range("E" & .Rows.Count).End(xlUp).row
        LastRow6 = .Range("D" & .Rows.Count).End(xlUp).row
        LastRow7 = .Range("C" & .Rows.Count).End(xlUp).row
        LastColumn = .Range("G5").End(xlToRight).Column
       
       For col = 7 To LastColumn
            For row = 6 To LastRow4
            .Range(Cells(row, col), Cells(row, col)).Value = Application.WorksheetFunction.Index(.Range(Cells(6, 5), Cells(LastRow5, 5)), _
            Application.WorksheetFunction.Match(.Range(Cells(row, 6), Cells(row, 6)), .Range(Cells(6, 4), Cells(LastRow6, 4)), 0), _
            Application.WorksheetFunction.Match(.Range(Cells(5, col), Cells(5, col)), .Range(Cells(6, 3), Cells(LastRow7, 3)), 0))
            Next row
        Next col
    End With
End Sub

When I start macro command, It finds first value (Max Voltage L1) but doesn't find other values (Max Voltage L2-3), gives an error:
1707337556233.png


Could you help me solve this problem?

Thank you!
 

Excel Facts

Copy a format multiple times
Select a formatted range. Double-click the Format Painter (left side of Home tab). You can paste formatting multiple times. Esc to stop
you're asking for Index match, however your formula is just Match. The format of the match formula is incorrect. This may be why it's erroring.
You will need to include the index function.
 
Upvote 0

Forum statistics

Threads
1,224,817
Messages
6,181,149
Members
453,021
Latest member
Justyna P

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