Jeremy4110
Board Regular
- Joined
- Sep 26, 2015
- Messages
- 70
I pull/extract supplier (name, address, numbers, etc) information from our system then I update and consolidate duplicate records. I set suppliers to inactive for only two reasons: 1.) There have been any sales in the last five years. 2.) They are a duplicate. The duplicates are reassigned to an active location. I have to track all the changes that I make. The extracted are pulled to a sheet called "Sup Loc Original" then copied to "Sup Loc Copy". I make changes and reassign duplicate records on the copy then upload the changes. Lastly I compare and track the changes made on a third sheet called "Dats Point" with the code below.
Here is my problem, I can only track the changes to every field and I need to be able track the changed information for inactive records and reassigned records as well. The code below isn't my creation, I altered it a little. What I would like to be able to do is delete the corresponding rows on the "Data Points" sheet that are active on the "Sup Loc Copy" sheet. The rows are identified with an "A" in column X. That way I can rerun the code to count and sum the information for the inactive locations. So basically if rows 2, 5, 7 and 8 are active on the "Sup Loc Copy" sheet then I need to delete those same rows on the "Data Points" sheet and I have no idea how to do that. I have looked for code that I could try to alter but have been unsuccessfully. Any help would be greatly appreciated.
Sub Data_Points_Compare2WorkSheets()
Sheets("Sup Loc COPY").Select
Sheets("Sup Loc COPY").Name = "Sup Loc COPY"
Cells.Select
ActiveWorkbook.Worksheets("Sup Loc COPY").Sort.SortFields.Clear
ActiveWorkbook.Worksheets("Sup Loc COPY").Sort.SortFields.Add Key:=Range( _
"A2:A10000"), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:= _
xlSortNormal
With ActiveWorkbook.Worksheets("Sup Loc COPY").Sort
.SetRange Range("A1:AZ10000")
.Header = xlYes
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With
Sheets("Sup Loc ORIGINAL").Select
Cells.Select
ActiveWorkbook.Worksheets("Sup Loc ORIGINAL").Sort.SortFields.Clear
ActiveWorkbook.Worksheets("Sup Loc ORIGINAL").Sort.SortFields.Add Key:=Range( _
"A2:A10000"), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:= _
xlSortNormal
With ActiveWorkbook.Worksheets("Sup Loc ORIGINAL").Sort
.SetRange Range("A1:AZ10000")
.Header = xlYes
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With
Sheets("Sheet3").Select
Sheets("Sheet3").Name = "Data Points"
Sheets("Data Points").Select
Dim ws1 As Worksheet
Dim ws2 As Worksheet
Set ws1 = Sheets("Sup Loc ORIGINAL")
Set ws2 = Sheets("Sup Loc COPY")
Dim ws1row As Long, ws2row As Long, ws1col As Integer, ws2col As Integer
Dim maxrow As Long, maxcol As Integer, colval1 As String, colval2 As String
Dim difference As Integer
Dim row As Long, col As Integer
With ws1.UsedRange
ws1row = .Rows.Count
ws1col = .Columns.Count
End With
With ws2.UsedRange
ws2row = .Rows.Count
ws2col = .Columns.Count
End With
maxrow = ws1row
maxcol = ws1col
If maxrow < ws2row Then maxrow = ws2row
If maxcol < ws2col Then maxcol = ws2col
difference = 0
For col = 1 To maxcol
For row = 1 To maxrow
colval1 = ""
colval2 = ""
colval1 = ws1.Cells(row, col).Formula
colval2 = ws2.Cells(row, col).Formula
If colval1 <> colval2 Then
difference = difference + 1
Cells(row, col).Formula = colval1 & " <> " & colval2
Cells(row, col).Interior.Color = 255
Cells(row, col).Font.ColorIndex = 2
Cells(row, col).Font.Bold = True
End If
Next row
Next col
Range("BA1:CP1").Value = "=COUNTA(R[1]C[-52]:R[10000]C[-52])"
Range("CQ1").Select
ActiveCell.FormulaR1C1 = "=SUM(RC[-42]:RC[-22],RC[-20]:RC[-7],RC[-4]:RC[-1])"
Range("BA1:CQ1").Select
Selection.Copy
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Application.CutCopyMode = False
End Sub
Here is my problem, I can only track the changes to every field and I need to be able track the changed information for inactive records and reassigned records as well. The code below isn't my creation, I altered it a little. What I would like to be able to do is delete the corresponding rows on the "Data Points" sheet that are active on the "Sup Loc Copy" sheet. The rows are identified with an "A" in column X. That way I can rerun the code to count and sum the information for the inactive locations. So basically if rows 2, 5, 7 and 8 are active on the "Sup Loc Copy" sheet then I need to delete those same rows on the "Data Points" sheet and I have no idea how to do that. I have looked for code that I could try to alter but have been unsuccessfully. Any help would be greatly appreciated.
Sub Data_Points_Compare2WorkSheets()
Sheets("Sup Loc COPY").Select
Sheets("Sup Loc COPY").Name = "Sup Loc COPY"
Cells.Select
ActiveWorkbook.Worksheets("Sup Loc COPY").Sort.SortFields.Clear
ActiveWorkbook.Worksheets("Sup Loc COPY").Sort.SortFields.Add Key:=Range( _
"A2:A10000"), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:= _
xlSortNormal
With ActiveWorkbook.Worksheets("Sup Loc COPY").Sort
.SetRange Range("A1:AZ10000")
.Header = xlYes
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With
Sheets("Sup Loc ORIGINAL").Select
Cells.Select
ActiveWorkbook.Worksheets("Sup Loc ORIGINAL").Sort.SortFields.Clear
ActiveWorkbook.Worksheets("Sup Loc ORIGINAL").Sort.SortFields.Add Key:=Range( _
"A2:A10000"), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:= _
xlSortNormal
With ActiveWorkbook.Worksheets("Sup Loc ORIGINAL").Sort
.SetRange Range("A1:AZ10000")
.Header = xlYes
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With
Sheets("Sheet3").Select
Sheets("Sheet3").Name = "Data Points"
Sheets("Data Points").Select
Dim ws1 As Worksheet
Dim ws2 As Worksheet
Set ws1 = Sheets("Sup Loc ORIGINAL")
Set ws2 = Sheets("Sup Loc COPY")
Dim ws1row As Long, ws2row As Long, ws1col As Integer, ws2col As Integer
Dim maxrow As Long, maxcol As Integer, colval1 As String, colval2 As String
Dim difference As Integer
Dim row As Long, col As Integer
With ws1.UsedRange
ws1row = .Rows.Count
ws1col = .Columns.Count
End With
With ws2.UsedRange
ws2row = .Rows.Count
ws2col = .Columns.Count
End With
maxrow = ws1row
maxcol = ws1col
If maxrow < ws2row Then maxrow = ws2row
If maxcol < ws2col Then maxcol = ws2col
difference = 0
For col = 1 To maxcol
For row = 1 To maxrow
colval1 = ""
colval2 = ""
colval1 = ws1.Cells(row, col).Formula
colval2 = ws2.Cells(row, col).Formula
If colval1 <> colval2 Then
difference = difference + 1
Cells(row, col).Formula = colval1 & " <> " & colval2
Cells(row, col).Interior.Color = 255
Cells(row, col).Font.ColorIndex = 2
Cells(row, col).Font.Bold = True
End If
Next row
Next col
Range("BA1:CP1").Value = "=COUNTA(R[1]C[-52]:R[10000]C[-52])"
Range("CQ1").Select
ActiveCell.FormulaR1C1 = "=SUM(RC[-42]:RC[-22],RC[-20]:RC[-7],RC[-4]:RC[-1])"
Range("BA1:CQ1").Select
Selection.Copy
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Application.CutCopyMode = False
End Sub