Macro VBA INDEX MATCH LOOKUP

XuanXuan

New Member
Joined
Nov 28, 2019
Messages
2
Office Version
  1. 2019
  2. 2016
Platform
  1. Windows
VBA Code:
Sub FindBeginEnd()

    Dim m As Long
    Dim Lastrow As Long
    Dim ws As Worksheet
    
    Set ws = Workbooks("TYPE A").Worksheets("Aimei Cheah Output")  
    Lastrow = Sheets(1).Cells(Rows.count, "A").End(xlUp).Row

    Range("AT4").Value = "Shortage Begin"
    Range("AU4").Value = "Shortage End"

    For m = 5 To Lastrow
        Cells(m, 46).Value = WorksheetFunction.Index(ws.Range("J3:V3"), WorksheetFunction.Match(True, ws.Range("J" & m & ":" & "V" & m) < 0, 0))
        Cells(m, 47).Value = WorksheetFunction.Lookup(2, 1 / (ws.Range("J" & m & ":" & "V" & m)), ws.Range("J" & m & ":" & "V" & m))
    Next m
    
End Sub

I tried many method to do this but can't work , anyone can help?
 

Excel Facts

Format cells as date
Select range and press Ctrl+Shift+3 to format cells as date. (Shift 3 is the # sign which sort of looks like a small calendar).
It is better if you tell us what you're trying to do. Code that doesn't work, doesn't always give an indication of your intention.

What is your code doing wrong? If you get an error message, what is that message and which line of the code causes it?

This is just a guess for the INDEX line
VBA Code:
Cells(m, 46).FormulaArray = "=INDEX('" & ws.Name & "'!J3:V3,MATCH(True,'" & ws.Name &"'!J" & m & ":" & "V" & m & "<0,0))"
Only typed it in here, so syntax not checked in vba editor.
 
Last edited:
Upvote 0

Forum statistics

Threads
1,223,897
Messages
6,175,271
Members
452,628
Latest member
dd2

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