I'm new to coding VBA development. I'm trying to have button in the Summary workbook that takes dates from an input file and puts it in a summary file. But I need to validate the project number because the order is not always the same and new lines may be added. And if any lines in the input file that are not in the summary file it will add it and highlight red. Example.
(Input File.xlsx)
Project No.: ___Location:____Project Description:___Start ____End
300 __________DET _______Electrical ___________09/04/16 __09/08/16
405 __________ATL _______ Basement __________ 04/01/14 __03/31/15
408 __________ATL ________Walls ______________03/02/15__09/25/15
414 __________ATL ________Plumbing ___________04/01/14 _03/31/15
400 __________PHL _______Sewage ___________ 09/01/16 __10/10/17
(Summary File.xlsm)
Project No.: _Location: __ Project Description:___ Start____End
408 ________ATL _______Walls ____________00/00/00 __00/00/00
405 ________ATL _______Basement ________00/00/00 __00/00/00
414 ________ATL _______Plumbing _________00/00/00 __00/00/00
** "Push Button in Summary File.xlsm" **
Summary File.xlsm now looks like:
Project No.: ________Location: ____Project Description: ____Start ______End
408 ________________ATL ________Walls _______________03/02/15 ___09/25/15
405 ________________ATL ________Basement ___________04/01/14 ___03/31/15
414 ________________ATL ________Plumbing ____________04/01/14 ___03/31/15
300"Highlight Red" ____DET _______Electrical ____________09/04/16 ___09/08/16
400"Highlight Red" ____PHL _______Sewage _____________09/01/16 ___10/10/17
Any code examples/help will be greatly appreciated. Thanks
Here is what I have so far:
Sub Compare(): Dim win As Worksheet, ws As Worksheet
Dim i As Long, s As Long, PNo As String, K, n As Long
Set win = Workbooks("InputFile.xlsx").Sheets("Sheet1")
Set ws = Workbooks("SummaryFile.xlsm").Sheets("Sheet1")
With CreateObject("Scripting.Dictionary")
s = win.Range("A:A").Find("*", , , , xlByRows, xlPrevious).Row
For i = 2 To s: PNo = Trim(win.Range("A" & i))
.Item(PNo) = i: Next i: K = .Keys()
s = ws.Range("A:A").Find("*", , , , xlByRows, xlPrevious).Row + 1
For n = LBound(K) To UBound(K)
For i = 2 To UBound(K) + 1: PNo = Trim(ws.Range("A" & i))
If K(n) = PNo Then
ws.Range("D" & i).Resize(1, 2).Value = _
win.Range("D" & .Item(K(n))).Resize(1, 2).Value
GoTo GetNext: End If: Next i
ws.Range("A" & s).Resize(1, 5).Value = _
win.Range("A" & .Item(K(n))).Resize(1, 5).Value
ws.Range("A" & s).Resize(1, 5).Interior.ColorIndex = 3
s = s + 1
GetNext: Next n
End With
End Sub