I wrote some code but its not completed because of my expertise in VBA. I have file consisting of 2 sheets. Sheet1 is current inventory and Sheet2 has orders.
Sheet2
[![enter image description here][1]][1]
Sheet1
[![enter image description here][2]][2]
I am looking for a help to complete the code. I just want that Code will pick up the Sheet2
Col"A" SKU's
and will match that in Sheet1
Col"A" SKU's
if same SKU's match.
Then
Code will search the nearest expiry date in Sheet1 Col"G"
for those SKU's which have been matched and will copy the same row for those SKU's which expiry is going to end soon. After that Paste that data into "NewSheet" (The purpose of Expiry date
is to sale those product which expiry is about to end so that we may not face the loss)
I have highlighted the Sheet1 Data with nearest expiry. your help will be much appreciated
MyCode.
Sub Copypaste()
Dim srchtrm As String
Dim rng As Range, destRow As Long
Dim shtSrc As Worksheet, shtDest As Worksheet
Dim c As Range
Dim i As Integer
Dim Today As Date
Set shtSrc = Sheet1
Set shtDest = Sheet2
destRow = 2
Sheets.Add.Name = "NewSheet"
Set rng = Application.Intersect(shtSrc.Range("A:A"), shtSrc.UsedRange)
For Each c In rng.Cells
If c.Value = Sheet1.Range("A2") Then
c.EntireRow.Copy Sheets("NewSheet").Cells(destRow, 1)
destRow = destRow + 1
End If
Next
End Sub
Code result in "New Sheet" [![enter image description here][3]][3]
Sheet Link https://drive.google.com/file/d/1yB1lsqm7K8Vk9EJMWRPHm05RDwTxVeKC/view?usp=sharing [1]: https://i.stack.imgur.com/v36cc.png [2]: https://i.stack.imgur.com/FVu2q.png [3]: https://i.stack.imgur.com/s6ygA.png