Option Explicit
Option Base 1
Sub DisributeRowsArrays()
' ~~ VBA - Copy and paste entire row to destination sheets based on cell value
' hiker95, 02/14/2014
' http://www.mrexcel.com/forum/excel-questions/685493-visual-basic-applications-move-rows-another-sheet-based-criteria-2.html#18
Dim shtSRC As Worksheet
Set shtSRC = ThisWorkbook.Worksheets("SRC_Weekly")
Dim shtSA As Worksheet, shtSAF As Worksheet
Dim shtSMC As Worksheet, shtSN As Worksheet
Set shtSA = Worksheets("SA_Weekly")
Set shtSAF = Worksheets("SAF_Weekly")
Set shtSMC = Worksheets("SMC_Weekly")
Set shtSN = Worksheets("SN_Weekly")
Dim arrSRC As Variant ' ~~ each group has its own array (incl master sht - "SRC_Weekly")
Dim arrA As Variant, arrF As Variant
Dim arrM As Variant, arrN As Variant
Dim aa As Integer, ff As Integer
Dim mm As Integer, nn As Integer
Dim cntr As Integer
Dim col As Integer
Dim LastColumn As Integer
Dim LastRow As Integer
shtSRC.Cells.WrapText = False 'Stop Text Wrapping
shtSA.Rows("3:100").Clear
shtSAF.Rows("3:100").Clear
shtSMC.Rows("3:100").Clear
shtSN.Rows("3:100").Clear
LastColumn = 8
'################ CAN IGNORE THIS SECTION ##############################
' ~~ Attempt to autocount used columns, but need to exclude any data in rows(1:2)
' ~~ Count last column in shtSRC, omitting header 2 rows || _
[url=http://strugglingtoexcel.com/2014/05/26/actual-used-range-excel-vba/]Get the Actual Used Range in a Spreadsheet | Struggling To Excel[/url] _
[url=http://stackoverflow.com/questions/9918785/excel-omitting-rows-columns-from-vba-macro]Excel: Omitting rows/columns from VBA macro - Stack Overflow[/url]
' LastColumn = ActualUsedRange(shtSRC).Cells(1).Offset(2, 0).Resize(ActualUsedRange(shtSRC).Rows.Count - 2, ActualUsedRange(shtSRC).Columns.Count)
' MsgBox LastColumn.Value
' [url]http://www.mrexcel.com/forum/excel-questions/619875-exclude-rows-usedrange.html[/url]
' Set arrSRC = Application.Intersect(ActualUsedRange(shtSRC), ActualUsedRange(shtSRC).Cells.Resize(Rows.Count - 2).Offset(2))
' LastColumn = arrSRC.Columns.Count
'#######################################################
' #####>>>>> ERROR HANDLING - THIS SECTION <<<<<#####
If shtSRC.FilterMode Then shtSRC.ShowAllData
arrSRC = shtSRC.Range("A3").CurrentRegion.Resize(, LastColumn) ' ~~ start reading in row 3 (after header), using 8 columns
cntr = Application.CountIf(shtSRC.Columns(4), "SA") ' ~~ col 4 = group
ReDim arrA(1 To cntr, 1 To LastColumn) '~~ chk for empty arrays & redim || [url=http://www.vbforums.com/showthread.php?372419-EXCEL-VBA-How-To-Deal-with-Empty-Dynamic-Arrays#2]EXCEL VBA: How To: Deal with Empty Dynamic Arrays ???-VBForums[/url]
cntr = Application.CountIf(shtSRC.Columns(4), "SAF")
ReDim arrF(1 To cntr, 1 To LastColumn)
cntr = Application.CountIf(shtSRC.Columns(4), "SMC")
ReDim arrM(1 To cntr, 1 To LastColumn)
cntr = Application.CountIf(shtSRC.Columns(4), "SN")
ReDim arrN(1 To cntr, 1 To LastColumn)
For cntr = 1 To UBound(arrSRC, 1)
If arrSRC(cntr, 4) = "SA" Then
aa = aa + 1
For col = 1 To LastColumn
arrA(aa, col) = arrSRC(cntr, col)
Next col
'original coding || traded in for for loops
' arrA(aa, 1) = arrSRC(cntr, 1)
' arrA(aa, 2) = arrSRC(cntr, 2)
' arrA(aa, 3) = arrSRC(cntr, 3)
' arrA(aa, 4) = arrSRC(cntr, 4)
' arrA(aa, 5) = arrSRC(cntr, 5)
' arrA(aa, 6) = arrSRC(cntr, 6)
' arrA(aa, 7) = arrSRC(cntr, 7)
' arrA(aa, 8) = arrSRC(cntr, 8)
ElseIf arrSRC(cntr, 4) = "SAF" Then
ff = ff + 1
For col = 1 To LastColumn
arrF(ff, col) = arrSRC(cntr, col)
Next col
ElseIf arrSRC(cntr, 4) = "SMC" Then
mm = mm + 1
For col = 1 To LastColumn
arrM(mm, col) = arrSRC(cntr, col)
Next col
ElseIf arrSRC(cntr, 4) = "SN" Then
nn = nn + 1
For col = 1 To LastColumn
arrN(nn, col) = arrSRC(cntr, col)
Next col
End If
Next cntr
LastRow = shtSA.Range("A" & Rows.Count).End(xlUp).Offset(1).Row
shtSA.Range("A" & LastRow).Resize(UBound(arrA, 1), LastColumn) = arrA
LastRow = shtSAF.Range("A" & Rows.Count).End(xlUp).Offset(1).Row
shtSAF.Range("A" & LastRow).Resize(UBound(arrF, 1), LastColumn) = arrF
LastRow = shtSMC.Range("A" & Rows.Count).End(xlUp).Offset(1).Row
shtSMC.Range("A" & LastRow).Resize(UBound(arrM, 1), LastColumn) = arrM
LastRow = shtSN.Range("A" & Rows.Count).End(xlUp).Offset(1).Row
shtSN.Range("A" & LastRow).Resize(UBound(arrN, 1), LastColumn) = arrN
End Sub