Wants to understand this VBA code
Hi Nick,
I want to understand this VBA code it simple align two sets of data to a new range, If you can provide line by line discription it would be great ...
*******************************************************************************************************
*******************************************************************************************************
»
Sub My Macro() Application.ScreenUpdating = False Application.Calculation = xlCalculationManual Application.EnableEvents = False '------------------ With ThisWorkbook.Worksheets("Sheet2") 'I will check here if sheet name is different Call CompareNCopy(.Range("B7"), .Range("H7"), .Range("N7")) 'For T-1 I will provide my own range Call CompareNCopy(.Range("H7"), .Range("B7"), .Range("T7")) 'For T-2 End With '================= Application.EnableEvents = True Application.Calculation = xlCalculationAutomatic Application.ScreenUpdating = True End Sub Sub CompareNCopy(rngOrg As Range, rngFrom As Range, rngTarget As Range) Dim rngCell As Range Dim intMatch As Integer rngTarget.CurrentRegion.Clear 'This will clear the target range rngOrg.CurrentRegion.Copy rngTarget.PasteSpecial xlPasteAll For Each rngCell In rngFrom.CurrentRegion.Columns(1).Cells intMatch = 0 On Error Resume Next intMatch = Application.WorksheetFunction.Match(rngCell.Value, rngOrg.CurrentRegion.Columns(1).Cells, 0) On Error GoTo 0 If intMatch = 0 Then 'rngCell.Resize(, rngFrom.CurrentRegion.Columns.Count).Copy rngCell.Resize(, 1).Copy rngTarget.End(xlDown).Offset(1).PasteSpecial xlPasteAll End If Next rngCell Application.CutCopyMode = False rngTarget.CurrentRegion.Sort Key1:=rngTarget, Order1:=xlAscending, Header:=xlGuess, _ OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom, _ DataOption1:=xlSortNormal Set rngCell = Nothing End Sub
Sub My Macro() ' NICK - this