Hi Mark,
Am Thu, 23 Jan 2020 22:04:00 -0800 (PST) schrieb
noodnutt@gmail.com:
I gives me this:
Date State Agency Code Agency Name Employee Name Employee Code Cost Centre Dept Grade Shift Total Hours $_Cost
Terri-anne 36.00 1519.95
Kerrieanne 16.00 662.64
Mary 7.50 303.45
Natalija 15.00 611.25
Marilyn 13.50 564.90
I would prefer to capture the data for all columns.
I would like this please:
Date State Agency Code Agency Name Employee Name Employee Code Cost Centre Dept Grade Shift Total Hours $_Cost
5/01/2020 NSW TA00015 Agency 1 Terri-anne 100000 T-28 Admin ADLV1 D 36.00 1519.95
5/01/2020 VIC TA00027 Agency Kerrieanne 100002 T-32 Admin ADLV1 D 16.00 662.64
5/01/2020 VIC TA00012 Agency 3 Mary 100003 T-06 Admin ADLV2 D 7.50 303.45
5/01/2020 VIC TA00027 Agency 4 Natalija 100004 T-32 Admin ADLV1 D 15.00 611.25
5/01/2020 SA TA00017 Agency 5 Marilyn 100005 T-58 Admin ADLV1 D 13.50 564.90
try:
Sub Test()
Dim sWS As Worksheet, tWS As Worksheet
Dim vData, vaData, varOut As Variant
Dim sHeader As String
Dim i As Integer, myCol As Integer
Dim LRow As Long, LCol As Long
Dim rngNames, rngHours, rngCost As Range
Set sWS = Sheets("Import 1")
Set tWS = Sheets("Import 2")
With sWS
LRow = .Cells(.Rows.Count, "A").End(xlUp).Row
LCol = .Cells(1, .Columns.Count).End(xlToLeft).Column
Set rngNames = .Range("E2:E" & LRow)
Set rngHours = .Range("K2:K" & LRow)
Set rngCost = .Range("L2:L" & LRow)
vData = rngNames
varOut = .Range(.Cells(2, 1), .Cells(LRow, LCol))
End With
sHeader = "Date,State,Agency Code,Agency Name,Employee Name,Employee
Code,Cost Centre,Dept,Grade,Shift,Total Hours,$_Cost"
vaData = Split(sHeader, ",")
With tWS
.Range("A1").Resize(, UBound(vaData) + 1) = vaData
With .Cells(2, 11).Resize(LRow - 1)
.Formula = "=Sumif('" & sWS.Name & "'!" & rngNames.Address & ",'" & sWS.Name & "'!" & rngNames(1, 1).Address(0, 0) & ",'" & sWS.Name & "'!" & rngHours.Address & ")"
.Value = .Value
End With
With .Cells(2, 12).Resize(LRow - 1)
.Formula = "=Sumif('" & sWS.Name & "'!" & rngNames.Address & ",'" & sWS.Name & "'!" & rngNames(1, 1).Address(0, 0) & ",'" & sWS.Name & "'!" & rngCost.Address & ")"
.Value = .Value
End With
For i = 1 To 10
myCol = Application.Match(.Cells(1, i), sWS.Range("1:1"), 0)
.Cells(2, i).Resize(LRow - 1) = Application.Index(varOut, 0, myCol)
Next
End With
End Sub
Regards
Claus B.
--
Windows10
Office 2016
--- SoupGate-Win32 v1.05
* Origin: fsxNet Usenet Gateway (21:1/5)