Index Match with Concatenate in VBA

Click22

New Member
Joined
Jan 29, 2020
Messages
15
Office Version
  1. 365
  2. 2016
Platform
  1. Windows
Hi,

I am trying to create an index match function within VBA.

The reason for this is that I would like to grab the required information and then for it to not update when a worksheet is calculated.

All of the information is in the same workbook.

The below image is from a sheet called "Stock Codes"

1580298747097.png


The below image is from a sheet called "Full Sheet"

1580299713143.png


What I am trying to achieve is that when I enter a part number in D:D on "Full Sheet" it will bring the Total on Order amount from "Stock Codes" (S:S) into the Total on Order field on "Full Sheet" (K:K)

I would also like to get the Next Del Qty from "Stock Codes" (T:T) and Next Del Date from "Stock Codes" (U:U) to concatenate into the Next Delivery filed on "Full Sheet" (L:L)

I can do this using index match formulas but as mentioned above, I don't want these values to recalculate. I would like them to be taken at a point in time (when the part number is entered).

I already have this code, which time stamps cell C:C when D:D has info entered in "Full Sheet".

1580300355028.png


Any help would be very much appreciated.
 

Excel Facts

Spell Check in Excel
Press F7 to start spell check in Excel. Be careful, by default, Excel does not check Capitalized Werds (whoops)
Assuming "Full Sheet" Last row in column D will be the part number to search for, then please check out the following code
Code:
Option Explicit
Sub MrExcelDotCom()
Dim cl As Object, lastRow As Long, strCells As String, partNumber As String, _
totalOnOrder As String, nextDelQty As String
With Sheets("Full Sheet")
    lastRow = .Cells(Rows.Count, 4).End(xlUp).Row
    strCells = "D" & lastRow
    partNumber = Range(strCells).Value
    With Sheets("Stock Codes")
        lastRow = .Cells(Rows.Count, 1).End(xlUp).Row
        strCells = "A1:A" & lastRow
        For Each cl In Sheets("Stock Codes").Range(strCells)
            If cl.Value = partNumber Then
                totalOnOrder = cl.Offset(0, 18).Value
                nextDelQty = cl.Offset(0, 19).Value & " " & cl.Offset(0, 20).Value
            End If
        Next cl
    End With
    lastRow = .Cells(Rows.Count, 11).End(xlUp).Row
    .Cells(lastRow, 11).Offset(1, 0).Value = totalOnOrder
    .Cells(lastRow, 12).Offset(1, 0).Value = nextDelQty
    .Columns("K:L").AutoFit
End With
End Sub
 
Upvote 0
Do you only ever have one row for each product in the sheet "Stock Codes"?
 
Upvote 0
Assuming "Full Sheet" Last row in column D will be the part number to search for, then please check out the following code
Code:
Option Explicit
Sub MrExcelDotCom()
Dim cl As Object, lastRow As Long, strCells As String, partNumber As String, _
totalOnOrder As String, nextDelQty As String
With Sheets("Full Sheet")
    lastRow = .Cells(Rows.Count, 4).End(xlUp).Row
    strCells = "D" & lastRow
    partNumber = Range(strCells).Value
    With Sheets("Stock Codes")
        lastRow = .Cells(Rows.Count, 1).End(xlUp).Row
        strCells = "A1:A" & lastRow
        For Each cl In Sheets("Stock Codes").Range(strCells)
            If cl.Value = partNumber Then
                totalOnOrder = cl.Offset(0, 18).Value
                nextDelQty = cl.Offset(0, 19).Value & " " & cl.Offset(0, 20).Value
            End If
        Next cl
    End With
    lastRow = .Cells(Rows.Count, 11).End(xlUp).Row
    .Cells(lastRow, 11).Offset(1, 0).Value = totalOnOrder
    .Cells(lastRow, 12).Offset(1, 0).Value = nextDelQty
    .Columns("K:L").AutoFit
End With
End Sub

Hi, I have pasted this in but it does not seem to be bringing any information through, also no errors are showing either.
 
Upvote 0
Assuming "Full Sheet" Last row in column D will be the part number to search for, then please check out the following code
Code:
Option Explicit
Sub MrExcelDotCom()
Dim cl As Object, lastRow As Long, strCells As String, partNumber As String, _
totalOnOrder As String, nextDelQty As String
With Sheets("Full Sheet")
    lastRow = .Cells(Rows.Count, 4).End(xlUp).Row
    strCells = "D" & lastRow
    partNumber = Range(strCells).Value
    With Sheets("Stock Codes")
        lastRow = .Cells(Rows.Count, 1).End(xlUp).Row
        strCells = "A1:A" & lastRow
        For Each cl In Sheets("Stock Codes").Range(strCells)
            If cl.Value = partNumber Then
                totalOnOrder = cl.Offset(0, 18).Value
                nextDelQty = cl.Offset(0, 19).Value & " " & cl.Offset(0, 20).Value
            End If
        Next cl
    End With
    lastRow = .Cells(Rows.Count, 11).End(xlUp).Row
    .Cells(lastRow, 11).Offset(1, 0).Value = totalOnOrder
    .Cells(lastRow, 12).Offset(1, 0).Value = nextDelQty
    .Columns("K:L").AutoFit
End With
End Sub

The part numbers entered into column D on "Full Sheet" isn't the last row. It is a shared workbook and each user has certain rows they can enter the part number in.
 
Upvote 0
Are you using the code in the same example table and sheets that you referenced?
 
Upvote 0
The part numbers entered into column D on "Full Sheet" isn't the last row. It is a shared workbook and each user has certain rows they can enter the part number in.
So how do you want to search for the part? If i dont grab the last cell in the column D, the code will not know where to grab it.
 
Upvote 0
So how do you want to search for the part? If i dont grab the last cell in the column D, the code will not know where to grab it.

I was hoping it would be able to use a similar way as the time stamp above, that when I entered a part number it would trigger the search.

I guess using the With Target statement?

Yes I had posted the code into the same example table I referenced.

Thanks
 
Upvote 0

Forum statistics

Threads
1,215,043
Messages
6,122,822
Members
449,096
Latest member
Erald

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