crazyeyeschase
Board Regular
- Joined
- May 6, 2014
- Messages
- 104
- Office Version
- 365
- Platform
- Windows
I have an excel sheet to manage parking for three different companies. Each company has their own document and my document then imports their sheet info a master document that I manage.
I then have a master sheet that imports all the info.
The problem I am having is that if two companies assign the same spot or if I fat finger something i cannot see that uness i search the spot number within all sheets.
The following code is what's used to pull the data from the other sheets into the maser sheet.
Is there a way to either search for duplicates in column F on the three different sheets and return a message that spot "X" has a duplicate"
Something that can be ran before the below macro or even during the same operation.
I then have a master sheet that imports all the info.
The problem I am having is that if two companies assign the same spot or if I fat finger something i cannot see that uness i search the spot number within all sheets.
The following code is what's used to pull the data from the other sheets into the maser sheet.
Is there a way to either search for duplicates in column F on the three different sheets and return a message that spot "X" has a duplicate"
Something that can be ran before the below macro or even during the same operation.
VBA Code:
Sub UpdateAll()
Dim sh4 As Worksheet
Dim dic As Object
Dim a As Variant, d As Variant, arrSh As Variant, aSh As Variant
Dim i As Long, nRow As Long
Set dic = CreateObject("Scripting.Dictionary")
Set sh4 = Sheets("All Parking")
arrSh = Array("Company 1", "Company 2", "Company 3")
On Error Resume Next
Sheet4.ShowAllData
On Error GoTo 0
d = sh4.Range("A1", sh4.Range("G" & Rows.Count).End(3)).Value2
For i = 1 To UBound(d)
dic(d(i, 7)) = i 'index for column G
Next
For Each aSh In arrSh
a = Sheets(aSh).Range("A2", Sheets(aSh).Range("F" & Rows.Count).End(3)).Value2
For i = 1 To UBound(a)
If dic.exists(a(i, 6)) Then 'compare column F with column G
nRow = dic(a(i, 6))
d(nRow, 1) = a(i, 1) 'copy A to A
d(nRow, 2) = a(i, 2) 'copy B to B
d(nRow, 3) = aSh 'sheet name
d(nRow, 4) = a(i, 3) 'copy C to D
d(nRow, 6) = a(i, 4) 'copy D to F
End If
Next i
Next aSh
sh4.Range("A1").Resize(UBound(d, 1), UBound(d, 2)).Value = d
End Sub