I need help creating a macro for cleaning up a csv sheet that contains product sales information including the shipping method that needs to be used. There are about 10 of our products that cannot be sent via our usual shipping methods and I need to overwrite the shipping method that is assigned to orders that contain these products.
If someone purchases multiple products in one order the order number is duplicated in the next row, the shipping method only displays in the first row with that order number and each consecutive product purchased in the same order just adds a new row with the product name in column B
I need to use VBA to check for a list of 10 or so specific products in column B and update the shipping method for the whole order (the upper most cell in column C that has the same value in cell A) if it contains one of these 10 products.
I think it needs to do something like this:
I would need this in a loop so that it does it for each instance of the search string in column B in the spreadsheet.
I hope this question is clear, I have searched SO and can't find an answer to this question. Any help or alternative fixes are welcome.
Try out the following code, given the setup and result in the following screenshots:
Sub test()
Dim pRange As Range
Dim nShip As Range
Set pRange = Range("E2")
pRange.Select
While ActiveCell.Value <> ""
Range("B2").Select
While ActiveCell.Value <> ""
If ActiveCell.Offset(0, -1).Value <> ActiveCell.Offset(-1, -1).Value Then
Set nShip = ActiveCell.Offset(0, 1)
End If
If ActiveCell.Value = pRange.Value Then
nShip.Value = pRange.Offset(0, 1).Value
ActiveCell.Offset(1, 0).Select
Else
ActiveCell.Offset(1, 0).Select
End If
Wend
Set pRange = pRange.Offset(1, 0)
pRange.Select
Wend
End Sub
Starting List:
Result after macro:
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.