Hi
I am having some serious problems with setting up a "double" array (cells in a row A:H and K:V) as a search variable.
Background:
My DATA sheet has some 50.000 lines and more (columns from A to K). I am splitting this table in multiple small files for specific users. After a while I collect the data back to my master file to sheet TEMP. Each row on sheet TEMP is unique within A:H range (as they originated from sheet DATA) and exactly the same unique row is available somewhere on sheet DATA. Only difference is in:
My Christmas wish is:
that someone helps me set up a code, that:
I did find two threads below, but I am truly short in understanding many basics in setting up array variables and then comparing these variables. I have cracked up some code for easier undestanding (below).
https://www.mrexcel.com/forum/excel-questions/484914-macro-adjustment-compare-two-sheets-2.html?highlight=excel+array+variant
https://www.mrexcel.com/forum/excel...olumns-display-differences-using-macro-2.html
Please help, thank you!
I am having some serious problems with setting up a "double" array (cells in a row A:H and K:V) as a search variable.
Background:
My DATA sheet has some 50.000 lines and more (columns from A to K). I am splitting this table in multiple small files for specific users. After a while I collect the data back to my master file to sheet TEMP. Each row on sheet TEMP is unique within A:H range (as they originated from sheet DATA) and exactly the same unique row is available somewhere on sheet DATA. Only difference is in:
- same unique array of cells in a row on sheet DATA is not in a same row as on sheet TEMP (these cells are never modified by end users) and
- values in range K:V may be different - these are regularly modified by end users
My Christmas wish is:
that someone helps me set up a code, that:
- sets up an array variant of each unique array A:H and corresponding K:V array from the same line on sheet TEMP,
- searches for same unique array A:H on sheet DATA,
- checks if there is any difference between K:V array on TEMP and DATA sheets
- updates K:V array on sheet DATA if it is not the same as K:V array from sheet TEMP
I did find two threads below, but I am truly short in understanding many basics in setting up array variables and then comparing these variables. I have cracked up some code for easier undestanding (below).
https://www.mrexcel.com/forum/excel-questions/484914-macro-adjustment-compare-two-sheets-2.html?highlight=excel+array+variant
https://www.mrexcel.com/forum/excel...olumns-display-differences-using-macro-2.html
Code:
Sub SyncMasterSheet()
Dim i As Long
Dim j As Long
i = 1
j = 1
'sheets set up
Dim SheetDATA As Worksheet
Dim SheetTEMP As Worksheet
Set SheetDATA = Worksheets("DATA")
Set SheetTEMP = Worksheets("TEMP")
'last row setup
Dim LastRowDATA As Long
Dim LastRowTEMP As Long
With SheetDATA
LastRowDATA = .Cells(.rows.Count, "A").End(xlUp).row
End With
With SheetTEMP
LastRowTEMP = .Cells(.rows.Count, "A").End(xlUp).row
End With
'full range setup
'Dim RangeDATA As Range
'Dim RangeTEMP As Range
'Set RangeDATA = SheetTEMP.Range(Cells(2, 1), Cells(LastRowDATA, 8))
'Set RangeTEMP = SheetTEMP.Range(Cells(2, 1), Cells(LastRowTEMP, 8))
Dim RangeDATA As Variant
Dim RangeTEMP As Variant
RangeDATA = SheetTEMP.Range(Cells(2, 1), Cells(LastRowDATA, 8))
RangeTEMP = SheetTEMP.Range(Cells(2, 1), Cells(LastRowTEMP, 8))
With SheetTEMP
For i = 2 To LastRowTEMP
Dim TEMPsearchARRAY1 As Variant
Dim TEMPsearchARRAY2 As Variant
TEMPsearchARRAY1 = Application.Range(Cell1:="TEMP!A" & i & ":" & "H" & i) 'this set of cells defines unique row entry and are fixed - no changes here
TEMPsearchARRAY2 = Application.Range(Cell1:="TEMP!K" & i & ":" & "V" & i) 'these cells are being constantly changed by users
With SheetDATA
For j = 2 To LastRowDATA
Dim DATArowNUMBER As Long
Dim DATAsearchARRAY1 As Variant
Dim DATAsearchARRAY2 As Variant
DATAsearchARRAY1 = Application.Range(Cell1:="DATA!A" & i & ":" & "H" & i) 'this set of cells defines unique row entry and are fixed
'no changes here (same on DATA and TEMP sheets)
Set DATAsearchARRAY1 = RangeDATA.Find(What:=TEMPsearchARRAY1, _
LookIn:=xlValues, _
LookAt:=xlWhole, _
SearchOrder:=xlByRows, _
SearchDirection:=xlNext, _
MatchCase:=False)
DATArowNUMBER = DATAsearchARRAY1.row
DATAsearchARRAY2 = Application.Range(Cell1:="DATA!K" & DATArowNUMBER & ":" & "V" & DATArowNUMBER) 'this is a point where if TEMPsearchARRAY2
'is different than DATAsearchARRAY2
'then TEMPsearchARRAY2 should replace DATAsearchARRAY2
If DATAsearchARRAY2 <> TEMPsearchARRAY2 Then
DATAsearchARRAY2 = TEMPsearchARRAY2
End If
Next j
End With
Next i
End With
Please help, thank you!