Sub Distribute_SRC_Weekly_V3()
' hiker95, 08/14/2015, ME874631
Dim wsrc As Worksheet, wsa As Worksheet, wsaf As Worksheet
Dim wsmc As Worksheet, wsn As Worksheet
Dim sa As Variant, nsa As Long
Dim saf As Variant, nsaf As Long
Dim smc As Variant, nsmc As Long
Dim sn As Variant, nsn As Long
Dim src As Variant, nsrc As Long
Dim i As Long, n As Long, lr As Long, c As Long
Application.ScreenUpdating = False
Set wsrc = Sheets("SRC_Weekly")
Set wsa = Sheets("SA_Weekly")
Set wsaf = Sheets("SAF_Weekly")
Set wsmc = Sheets("SMC_Weekly")
Set wsn = Sheets("SN_Weekly")
lr = wsa.Cells(Rows.Count, 1).End(xlUp).Row
If lr > 2 Then wsa.Range("A3:H" & lr).Clear
lr = wsaf.Cells(Rows.Count, 1).End(xlUp).Row
If lr > 2 Then wsaf.Range("A3:H" & lr).Clear
lr = wsmc.Cells(Rows.Count, 1).End(xlUp).Row
If lr > 2 Then wsmc.Range("A3:H" & lr).Clear
lr = wsn.Cells(Rows.Count, 1).End(xlUp).Row
If lr > 2 Then wsn.Range("A3:H" & lr).Clear
With wsrc
.Activate
.UsedRange.Cells.WrapText = False
If .FilterMode = True Then .ShowAllData
lr = .Cells(Rows.Count, 1).End(xlUp).Row
If lr = 2 Then
Application.ScreenUpdating = True
MsgBox ("Sheet SRC_Weekly does not contain any raw data - macro terminated!")
Exit Sub
End If
src = .Range("A3:H" & lr)
n = Application.CountIf(.Range("D3:D" & lr), "SA")
If n > 0 Then ReDim sa(1 To n, 1 To 8)
n = Application.CountIf(.Range("D3:D" & lr), "SAF")
If n > 0 Then ReDim saf(1 To n, 1 To 8)
n = Application.CountIf(.Range("D3:D" & lr), "SMC")
If n > 0 Then ReDim smc(1 To n, 1 To 8)
n = Application.CountIf(.Range("D3:D" & lr), "SN")
If n > 0 Then ReDim sn(1 To n, 1 To 8)
End With
For i = LBound(src, 1) To UBound(src, 1)
If src(i, 4) = "SA" Then
nsa = nsa + 1
For c = 1 To 8
sa(nsa, c) = src(i, c)
Next c
ElseIf src(i, 4) = "SAF" Then
nsaf = nsaf + 1
For c = 1 To 8
saf(nsaf, c) = src(i, c)
Next c
ElseIf src(i, 4) = "SMC" Then
nsmc = nsmc + 1
For c = 1 To 8
smc(nsmc, c) = src(i, c)
Next c
ElseIf src(i, 4) = "SN" Then
nsn = nsn + 1
For c = 1 To 8
sn(nsn, c) = src(i, c)
Next c
End If
Next i
If nsa > 0 Then
wsa.Range("A3").Resize(UBound(sa, 1)).NumberFormat = "@"
wsa.Range("A3").Resize(UBound(sa, 1), UBound(sa, 2)) = sa
wsa.Range("F3").Resize(UBound(sa, 1)).NumberFormat = "m/d/yyyy"
wsa.Range("G3").Resize(UBound(sa, 1)).HorizontalAlignment = xlCenter
wsa.Columns("A:H").AutoFit
End If
If nsaf > 0 Then
wsaf.Range("A3").Resize(UBound(saf, 1)).NumberFormat = "@"
wsaf.Range("A3").Resize(UBound(saf, 1), UBound(saf, 2)) = sa
wsaf.Range("F3").Resize(UBound(saf, 1)).NumberFormat = "m/d/yyyy"
wsaf.Range("G3").Resize(UBound(saf, 1)).HorizontalAlignment = xlCenter
wsaf.Columns("A:H").AutoFit
End If
If nsmc > 0 Then
wsmc.Range("A3").Resize(UBound(smc, 1)).NumberFormat = "@"
wsmc.Range("A3").Resize(UBound(smc, 1), UBound(smc, 2)) = sa
wsmc.Range("F3").Resize(UBound(smc, 1)).NumberFormat = "m/d/yyyy"
wsmc.Range("G3").Resize(UBound(smc, 1)).HorizontalAlignment = xlCenter
wsmc.Columns("A:H").AutoFit
End If
If nsn > 0 Then
wsn.Range("A3").Resize(UBound(sn, 1)).NumberFormat = "@"
wsn.Range("A3").Resize(UBound(sn, 1), UBound(sn, 2)) = sn
wsn.Range("F3").Resize(UBound(sn, 1)).NumberFormat = "m/d/yyyy"
wsn.Range("G3").Resize(UBound(sn, 1)).HorizontalAlignment = xlCenter
wsn.Columns("A:H").AutoFit
End If
wsrc.Activate
Application.ScreenUpdating = True
End Sub