VBA macro for transposing row and columns based on one condition

nn992

New Member
Joined
Jul 28, 2016
Messages
47
I am trying to manage time sheet of my company and have a small issue. I have data ordered in rows per person, however I would like to have them in column format. Currently, data is in following format:

ErZ4t.png



I would like it to have the following shape:
Rules that are to be followed: withing the same name(person) and same date, take the "OUT" time value and put it to the next row. Please note that there are few thousand rows.

LlJYj.png

Questions are very welcome Many thanks in advance!
 

Excel Facts

How to total the visible cells?
From the first blank cell below a filtered data set, press Alt+=. Instead of SUM, you will get SUBTOTAL(9,)
Try this VBA code:
Code:
Sub MyMacro()

    Dim lr As Long
    
'   Find last row with data in column C
    lr = Cells(Rows.Count, "C").End(xlUp).Row

'   Put header on column E
    Range("E1") = "Out"

'   Copy values from column C to column E, shifting up one row
    Range("C3:C" & lr).Copy Range("E2")
    
'   Removes "OUT" values in column D
    Application.DisplayAlerts = False
    Columns("D:D").Replace What:="OUT", Replacement:="", LookAt:=xlWhole, _
        SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
        ReplaceFormat:=False
    Application.DisplayAlerts = True
    
'   Remove rows with blanks in column D
    Range("D1:D" & lr).SpecialCells(xlCellTypeBlanks).EntireRow.Delete
    
'   Remove column D
    Columns("D:D").Delete
    
End Sub
 
Upvote 0

Forum statistics

Threads
1,213,531
Messages
6,114,167
Members
448,554
Latest member
Gleisner2

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