Hi,
I have been using this code for the past year and it has worked really well in almost all cases, but some of our manufacturers don't think about how their skus are written. The problem is this new manufacturer uses multiple dashes in about 20% of their products and this makes my code not work.
An example is: 49-44035-P
This one also does not work: 73-10102M
These do work fine:44-FF010
51-10732
49-44023
If anyone has an idea on how i can manipulate it to work better, i would greatly appreciate it! I was considering changing the variables to Strings instead of Integers, but i ran into some complications with this.
Thank you.
I have been using this code for the past year and it has worked really well in almost all cases, but some of our manufacturers don't think about how their skus are written. The problem is this new manufacturer uses multiple dashes in about 20% of their products and this makes my code not work.
An example is: 49-44035-P
This one also does not work: 73-10102M
These do work fine:44-FF010
51-10732
49-44023
If anyone has an idea on how i can manipulate it to work better, i would greatly appreciate it! I was considering changing the variables to Strings instead of Integers, but i ran into some complications with this.
Thank you.
Code:
Sub ReplacePriceMatch()
Dim ws As Worksheet
Dim ws2 As Worksheet
Dim sourceRow1 As Integer
Dim sourceCol1 As Integer
Dim sourceRow2 As Integer
Dim sourceCol2 As Integer
Dim destinationRow As Integer
Dim destinationCol As Integer
Dim fromRow As Integer
Dim fromCol As Integer
sourceRow1 = 2 'The starting row of the manufacturer part number off of the price list
sourceCol1 = 7 'The starting column of the manufacturer part number off of the price list
destinationRow = sourceRow1 'The starting row of the destination path where you want to change the prices
destinationCol = sourceCol1 + 4 'The starting row of the destination path where you want to change the prices Usually 3 for MSRP and 4 for MAP
fromCol = 4 'The source column where you want to grab prices from and update our price list with Usually 4 for MAP and 5 for MSRP
Set ws = ActiveWorkbook.Sheets("Sheet1") 'Original price file, for accuracy use the name of the file. (best results use CSV files)
Set ws2 = ActiveWorkbook.Sheets("Sheet2") 'New file for update comparisons, for accuracy use the name of the file. (best results use CSV files)
Do
sourceRow2 = 3
sourceCol2 = 1
Do
If ws.Cells(sourceRow1, sourceCol1).Value = ws2.Cells(sourceRow2, sourceCol2).Value Then
destinationRow = sourceRow1
ws.Cells(destinationRow, destinationCol).Value = ws2.Cells(sourceRow2, fromCol).Value
ws.Cells(destinationRow, destinationCol).Interior.ColorIndex = 38 'Index color for the interior of the cell, 38 = Hot Pink (oh my), other values are 1:black, 3:red etc...
End If
sourceRow2 = sourceRow2 + 1
Loop While sourceRow2 <= 2600 'Find the max number of lines from the ws2 worksheet, input that number here
sourceRow1 = sourceRow1 + 1
Loop While sourceRow1 <= 432 'Find the max number of lines from the ws worksheet, input that number here
End Sub