Macro help?

shayalsamawi

New Member
Joined
Sep 9, 2021
Messages
16
Office Version
  1. 365
Platform
  1. Windows
Hi All,

This is my first post - thanks so much in advance for helping.

I have data that looks like this:

ProjectSubprojectSamTomTerryAlice
Project 1Subproject b
4​
1​
6​
Project 2subproject d
5​
4​
5​
Project 3subproject f
3​
3​
6​
Project 4subproject q
4​

It's a time sheet with names of individuals and how many hours they spent on each task.

I need it to look like this:

samproject 1subproject b
4​
samproject 3subproject f
3​
TomProject 2Subproject d
5​

so - removing any cells with no hours, the data is almost transposed with the name, project, subproject and hours.

I have to do this sheet weekly, which is why I wanted a macro to hopefully speed the process up.

I'd massively massively appreciate any help

Thanks
Shay
 

Excel Facts

Convert text numbers to real numbers
Select a column containing text numbers. Press Alt+D E F to quickly convert text to numbers. Faster than "Convert to Number"
Easy using Power Query instead of VBA.

Book1
ABCDEFGHIJK
1ProjectSubprojectSamTomTerryAliceNameProjectSubprojectHours Spent
2Project 1Subproject b416SamProject 1Subproject b4
3Project 2subproject d545TomProject 1Subproject b1
4Project 3subproject f336AliceProject 1Subproject b6
5Project 4subproject q4TomProject 2subproject d5
6TerryProject 2subproject d4
7AliceProject 2subproject d5
8SamProject 3subproject f3
9TerryProject 3subproject f3
10AliceProject 3subproject f6
11TerryProject 4subproject q4
Sheet1


Power Query:
let
    Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
    Type = Table.TransformColumnTypes(Source,{{"Project", type text}, {"Subproject", type text}, {"Sam", type text}, {"Tom", type text}, {"Terry", type text}, {"Alice", type text}}),
    UOC = Table.UnpivotOtherColumns(Type, {"Project", "Subproject"}, "Name", "Hours Spent"),
    Reorder = Table.ReorderColumns(UOC,{"Name", "Project", "Subproject", "Hours Spent"})
in
    Reorder
 
Upvote 0
Hi & welcome to MrExcel.
How about
VBA Code:
Sub shayalsamawi()
   Dim Ary As Variant, Nary As Variant
   Dim r As Long, c As Long, nr As Long
   
   Ary = Sheets("Sheet1").Range("A1").CurrentRegion.Value2
   ReDim Nary(1 To UBound(Ary) * UBound(Ary, 2), 1 To 4)
   For c = 3 To UBound(Ary, 2)
      For r = 2 To UBound(Ary)
         If Ary(r, c) <> "" Then
            nr = nr + 1
            Nary(nr, 1) = Ary(1, c)
            Nary(nr, 2) = Ary(r, 1)
            Nary(nr, 3) = Ary(r, 2)
            Nary(nr, 4) = Ary(r, c)
         End If
      Next r
   Next c
   Sheets("Sheet2").Range("A2").Resize(nr, 4).Value = Nary
End Sub
Change sheet names to suit.
 
Upvote 0
Hi & welcome to MrExcel.
How about
VBA Code:
Sub shayalsamawi()
   Dim Ary As Variant, Nary As Variant
   Dim r As Long, c As Long, nr As Long
  
   Ary = Sheets("Sheet1").Range("A1").CurrentRegion.Value2
   ReDim Nary(1 To UBound(Ary) * UBound(Ary, 2), 1 To 4)
   For c = 3 To UBound(Ary, 2)
      For r = 2 To UBound(Ary)
         If Ary(r, c) <> "" Then
            nr = nr + 1
            Nary(nr, 1) = Ary(1, c)
            Nary(nr, 2) = Ary(r, 1)
            Nary(nr, 3) = Ary(r, 2)
            Nary(nr, 4) = Ary(r, c)
         End If
      Next r
   Next c
   Sheets("Sheet2").Range("A2").Resize(nr, 4).Value = Nary
End Sub
Change sheet names to suit.
 
Upvote 0
Hi & welcome to MrExcel.
How about
VBA Code:
Sub shayalsamawi()
   Dim Ary As Variant, Nary As Variant
   Dim r As Long, c As Long, nr As Long
  
   Ary = Sheets("Sheet1").Range("A1").CurrentRegion.Value2
   ReDim Nary(1 To UBound(Ary) * UBound(Ary, 2), 1 To 4)
   For c = 3 To UBound(Ary, 2)
      For r = 2 To UBound(Ary)
         If Ary(r, c) <> "" Then
            nr = nr + 1
            Nary(nr, 1) = Ary(1, c)
            Nary(nr, 2) = Ary(r, 1)
            Nary(nr, 3) = Ary(r, 2)
            Nary(nr, 4) = Ary(r, c)
         End If
      Next r
   Next c
   Sheets("Sheet2").Range("A2").Resize(nr, 4).Value = Nary
End Sub
Change sheet names to suit.
Hi,

Thank you so much for this. You're officially my favourite person hahaha

It's not working - I'm not sure why.

When I click on the tab 'view' and then 'run macros' - it's not there?

Book123.xlsm
CDEFGHIJKLMNOPQRS
212/09/2021
3
4Sub Ledger
5Sub Ledger106324610127410632110655317113425288861006501195261418166101053273969163932610122461005376101203106313
612345678910111213141516
7Person 1Person 2Person 3Person 4Person 5Person 6Person 7Person 8Person 9Person 10Person 11Person 12Person 13Person 14Person 15Person 16
8Sub LedgerUncompleted HoursUncompleted HoursUncompleted HoursFinished HoursUncompleted HoursUncompleted HoursUncompleted HoursUncompleted HoursUncompleted HoursUncompleted HoursUncompleted HoursUncompleted HoursUncompleted HoursUncompleted HoursUncompleted HoursUncompleted Hours
9SM
10PS
11AS
12CS
13HD
14A
15L
16B
17T
18S
19TOIL
20O
21052L2, 10
22052L3, 103437
23052L3, 20
24052L1, 10
25052L1, 20
26052L1, 30
27052L4, 10
28052L21, 10
29052L12, 130
30052L13,10
31052L20, 10
32052L26, 10
33052L27, 10
34052L28, 10
35052L14, 10
36052L24,10
37052L24,20
38052L24,30
39052L24,40
40052L24,50
41052L24,60
42052L29, 10
43052L30, 10
44052L38, 10
45052L31, 10
46052L32, 10
47052L33, 10
48052L34, 10
49052L35, 10
50052L38, 10
51052L37, 10
52052J926
53052J777
54052J2750
55052X002
56052X013
57052X218
58052X902
59052X898
60052X945
61052X784
62052X981
63052X973
64052X1018
65
66SUPP
67
68052X890
69052X1022
70052X984
71052X1021
72052L36, 10
73052X1033
74052X1039
Sheet1
Cell Formulas
RangeFormula
D8:S8D8=IF(SUM(D9:D100)>36.99,"Finished Hours","Uncompleted Hours")
Cells with Conditional Formatting
CellConditionCell FormatStop If True
D8:S8Cell Valuecontains "Finished Hours"textNO
I14Cell Valuecontains "Finished"textNO
D8:S8Cell Valuecontains "Uncompleted Hours"textNO
D9Cell Valuecontains ""Uncompleted Hours""textNO
 
Upvote 0
Easy using Power Query instead of VBA.

Book1
ABCDEFGHIJK
1ProjectSubprojectSamTomTerryAliceNameProjectSubprojectHours Spent
2Project 1Subproject b416SamProject 1Subproject b4
3Project 2subproject d545TomProject 1Subproject b1
4Project 3subproject f336AliceProject 1Subproject b6
5Project 4subproject q4TomProject 2subproject d5
6TerryProject 2subproject d4
7AliceProject 2subproject d5
8SamProject 3subproject f3
9TerryProject 3subproject f3
10AliceProject 3subproject f6
11TerryProject 4subproject q4
Sheet1


Power Query:
let
    Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
    Type = Table.TransformColumnTypes(Source,{{"Project", type text}, {"Subproject", type text}, {"Sam", type text}, {"Tom", type text}, {"Terry", type text}, {"Alice", type text}}),
    UOC = Table.UnpivotOtherColumns(Type, {"Project", "Subproject"}, "Name", "Hours Spent"),
    Reorder = Table.ReorderColumns(UOC,{"Name", "Project", "Subproject", "Hours Spent"})
in
    Reorder

Hi,

Thank you so much for this - I'm honestly so grateful for your kind help.

I can't do this - not sure why.

Thanks so so much again.

This is my data:

Book123.xlsm
CDEFGHIJKLMNOPQRS
5Sub Ledger106324610127410632110655317113425288861006501195261418166101053273969163932610122461005376101203106313
612345678910111213141516
7Person 1Person 2Person 3Person 4Person 5Person 6Person 7Person 8Person 9Person 10Person 11Person 12Person 13Person 14Person 15Person 16
8Sub LedgerUncompleted HoursUncompleted HoursUncompleted HoursFinished HoursUncompleted HoursUncompleted HoursUncompleted HoursUncompleted HoursUncompleted HoursUncompleted HoursUncompleted HoursUncompleted HoursUncompleted HoursUncompleted HoursUncompleted HoursUncompleted Hours
9SM
10PS
11AS
12CS
13HD
14A
15L
16B
17T
18S
19TOIL
20O
21052L2, 10
22052L3, 103437
23052L3, 20
24052L1, 10
25052L1, 20
26052L1, 30
27052L4, 102
28052L21, 102
29052L12, 130
30052L13,10
31052L20, 10
32052L26, 10
33052L27, 10
34052L28, 10
35052L14, 10
36052L24,10
37052L24,20
38052L24,30
39052L24,40
40052L24,50
41052L24,60
42052L29, 10
43052L30, 10
44052L38, 10
45052L31, 10
46052L32, 10
47052L33, 10
48052L34, 10
49052L35, 10
50052L38, 10
51052L37, 10
52052J926
53052J777
54052J2750
55052X002
56052X013
57052X218
58052X902
59052X898
60052X945
61052X784
62052X981
63052X973
64052X1018
65
66SUPP
67
68052X890
69052X1022
70052X984
71052X1021
72052L36, 10
73052X1033
74052X1039
Sheet1
Cell Formulas
RangeFormula
D8:S8D8=IF(SUM(D9:D100)>36.99,"Finished Hours","Uncompleted Hours")
Cells with Conditional Formatting
CellConditionCell FormatStop If True
D8:S8Cell Valuecontains "Finished Hours"textNO
I14Cell Valuecontains "Finished"textNO
D8:S8Cell Valuecontains "Uncompleted Hours"textNO
D9Cell Valuecontains ""Uncompleted Hours""textNO
 
Upvote 0
It's not working - I'm not sure why.
On reason is that your data bears no resemblance to what you originally posted.
Given the data you have now posted, what should the outcome be?
 
Upvote 0
Hi Fluff,

Ahh - I'm sorry

Here's my data:

Book123.xlsm
ABCDEFGHIJKLMNOP
1
2Week Ending12/09/2021
3
4Project DescriptionSub LedgerUncompleted HoursUncompleted HoursUncompleted HoursFinished HoursUncompleted HoursUncompleted HoursUncompleted HoursUncompleted HoursUncompleted HoursUncompleted HoursUncompleted HoursUncompleted HoursUncompleted Hours
5Person 1Person 2Person 3Person 4Person 5Person 6Person 7Person 8Person 9Person 10Person 11Person 12Person 13
6Project DescriptionSubledger1063246101274106321106553171134252888610065011952614181661010532739691639326101224
7Indirect TimeAdmin - Sales + MarketingSM
8Admin - Product SupportPS
9Admin - Applications SupportAS
10Admin - Customer SupportCS
11Customer Support (Help Desk)HD
12Admin - GeneralA23
13LeaveL
14Bank HolidayB
15TrainingT
16SickS1
17Time Off in LieuTOIL
18OtherO
19Development ProgrammePRODUCT SUPPORT - Pulsar/Firebird052L2, 10
20PRODUCT SUPPORT - Rockcore Product Support052L3, 103437
21PRODUCT SUPPORT - Overburden052L3, 20
22PRODUCT SUPPORT - MQC052L1, 10
23PRODUCT SUPPORT - CEM052L1, 20
24PRODUCT SUPPORT - LEXMAR052L1, 30
25PRODUCT SUPPORT - MQR052L4, 102
26Hypersense Product Support052L21, 102
27Productionisation052L12, 130
2890 80MHz Halbach052L13,10
29Overburden Mk2052L20, 10
30MQC-R052L26, 10
31Q-Sense MQC052L27, 10
32Automation for X-Pulse052L28, 10
33AZUL052L14, 10
34BLOC - Work Package 1052L24,10
35BLOC - Work Package 2052L24,20
36BLOC - Work Package 3052L24,30
37BLOC - Work Package 4052L24,40
38BLOC - Work Package 5052L24,50
39BLOC - Work Package 6052L24,60
40Spinflow V3.1052L29, 10
41External lock for X-Pulse052L30, 10
42Switched Probe X-Pulse052L38, 10
43X-Pulse 80/Cost Down052L31, 10
44Halbach 20052L32, 10
45MQC HT052L33, 10
46Spin Studio Application Releases - Toothpaste052L34, 10
47Spin Echo (Grant)052L35, 10
48X-Pulse Probe052L38, 10
49Nottingham Trent University052L37, 10
Sheet1
Cell Formulas
RangeFormula
D4:P4D4=IF(SUM(D7:D94)>36.99,"Finished Hours","Uncompleted Hours")
Cells with Conditional Formatting
CellConditionCell FormatStop If True
D4:S4Cell Valuecontains "Finished Hours"textNO
D4:S4Cell Valuecontains "Uncompleted Hours"textNO
D6:S6Cell Valuecontains "Finished Hours"textNO
I12Cell Valuecontains "Finished"textNO
D6:S6Cell Valuecontains "Uncompleted Hours"textNO
D7Cell Valuecontains ""Uncompleted Hours""textNO


I want it to look like this:

Book123.xlsm
NOP
19106324052L3, 108
20106324052L1, 203
216101274052L1, 204
Sheet2


So - person ID, project code (denoted on main sheet as subledger) and hours (missing any cells where there is no data). I can't thank you enough for your help - thanks so so much!!!
 
Upvote 0
On reason is that your data bears no resemblance to what you originally posted.
Given the data you have now posted, what should the outcome be?
Hi Fluff,

Ahh - I'm sorry

Here's my data:

Book123.xlsm
ABCDEFGHIJKLMNOP
1
2Week Ending12/09/2021
3
4Project DescriptionSub LedgerUncompleted HoursUncompleted HoursUncompleted HoursFinished HoursUncompleted HoursUncompleted HoursUncompleted HoursUncompleted HoursUncompleted HoursUncompleted HoursUncompleted HoursUncompleted HoursUncompleted Hours
5Person 1Person 2Person 3Person 4Person 5Person 6Person 7Person 8Person 9Person 10Person 11Person 12Person 13
6Project DescriptionSubledger1063246101274106321106553171134252888610065011952614181661010532739691639326101224
7Indirect TimeAdmin - Sales + MarketingSM
8Admin - Product SupportPS
9Admin - Applications SupportAS
10Admin - Customer SupportCS
11Customer Support (Help Desk)HD
12Admin - GeneralA23
13LeaveL
14Bank HolidayB
15TrainingT
16SickS1
17Time Off in LieuTOIL
18OtherO
19Development ProgrammePRODUCT SUPPORT - Pulsar/Firebird052L2, 10
20PRODUCT SUPPORT - Rockcore Product Support052L3, 103437
21PRODUCT SUPPORT - Overburden052L3, 20
22PRODUCT SUPPORT - MQC052L1, 10
23PRODUCT SUPPORT - CEM052L1, 20
24PRODUCT SUPPORT - LEXMAR052L1, 30
25PRODUCT SUPPORT - MQR052L4, 102
26Hypersense Product Support052L21, 102
27Productionisation052L12, 130
2890 80MHz Halbach052L13,10
29Overburden Mk2052L20, 10
30MQC-R052L26, 10
31Q-Sense MQC052L27, 10
32Automation for X-Pulse052L28, 10
33AZUL052L14, 10
34BLOC - Work Package 1052L24,10
35BLOC - Work Package 2052L24,20
36BLOC - Work Package 3052L24,30
37BLOC - Work Package 4052L24,40
38BLOC - Work Package 5052L24,50
39BLOC - Work Package 6052L24,60
40Spinflow V3.1052L29, 10
41External lock for X-Pulse052L30, 10
42Switched Probe X-Pulse052L38, 10
43X-Pulse 80/Cost Down052L31, 10
44Halbach 20052L32, 10
45MQC HT052L33, 10
46Spin Studio Application Releases - Toothpaste052L34, 10
47Spin Echo (Grant)052L35, 10
48X-Pulse Probe052L38, 10
49Nottingham Trent University052L37, 10
Sheet1
Cell Formulas
RangeFormula
D4:P4D4=IF(SUM(D7:D94)>36.99,"Finished Hours","Uncompleted Hours")
Cells with Conditional Formatting
CellConditionCell FormatStop If True
D4:S4Cell Valuecontains "Finished Hours"textNO
D4:S4Cell Valuecontains "Uncompleted Hours"textNO
D6:S6Cell Valuecontains "Finished Hours"textNO
I12Cell Valuecontains "Finished"textNO
D6:S6Cell Valuecontains "Uncompleted Hours"textNO
D7Cell Valuecontains ""Uncompleted Hours""textNO


I want it to look like this:

Book123.xlsm
NOP
19106324052L3, 108
20106324052L1, 203
216101274052L1, 204
Sheet2


So - person ID, project code (denoted on main sheet as subledger) and hours (missing any cells where there is no data). I can't thank you enough for your help - thanks so so much!!!
 
Upvote 0
This is absolutely nothing like what you originally asked for, so how do you expect any solution to work? All you have done is waste our time & yours. :(
Can you explain where those numbers in you output col P come from as they do not appear in your data.
 
Upvote 0

Forum statistics

Threads
1,223,934
Messages
6,175,490
Members
452,649
Latest member
mr_bhavesh

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top