Microsoft Office Forums

Go Back   Microsoft Office Forums > >

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #2  
Old 03-12-2016, 01:46 PM
ld_kt12 ld_kt12 is offline data manipulation Windows 10 data manipulation Office 2016
Novice
 
Join Date: Mar 2016
Location: UK
Posts: 1
ld_kt12 is on a distinguished road
Smile This code may solve your problem

Sub transform_data()
'
'
'
Dim td_dates, td_emp_ids, td_shifts, td_data_rows, td_data_cols
Dim td_count1, td_count2, td_count3, td_last_shift, td_last_date, td_this_shift, td_this_date
'
Sheets("Sheet2").Select
Range("A1").Select
Range(Selection, Selection.End(xlDown)).Select
td_data_rows = Selection.Rows.Count
Range("A1").Select
td_data_cols = Range(Selection, Selection.End(xlToRight)).Select
td_data_cols = Selection.Columns.Count
td_dates = Range("a1").Offset(0, 3).Resize(1, td_data_cols - 3).Value
td_emp_ids = Range("a1").Offset(1, 1).Resize(td_data_rows - 1, 1).Value
td_shifts = Range("a1").Offset(1, 3).Resize(td_data_rows - 1, td_data_cols - 3).Value
Sheets("Sheet1").Select

td_count3 = 1
For td_count1 = 1 To td_data_rows - 1
td_count3 = td_count3 + 1
td_last_shift = td_shifts(td_count1, 1)
td_last_date = td_dates(1, 1)
Cells(td_count3, 1) = td_emp_ids(td_count1, 1)
Cells(td_count3, 2) = td_last_shift
Cells(td_count3, 3) = td_last_date
For td_count2 = 2 To td_data_cols - 3
td_this_shift = td_shifts(td_count1, td_count2)
td_this_date = td_dates(1, td_count2)
If (td_this_shift = td_last_shift) Then
td_last_date = td_this_date
Else
Cells(td_count3, 4) = td_last_date
td_count3 = td_count3 + 1
Cells(td_count3, 1) = td_emp_ids(td_count1, 1)
Cells(td_count3, 2) = td_this_shift
Cells(td_count3, 3) = td_this_date
td_last_shift = td_this_shift
td_last_date = td_this_date
End If
Next
Cells(td_count3, 4) = td_last_date
Next
End Sub
Reply With Quote
 



Similar Threads
Thread Thread Starter Forum Replies Last Post
data manipulation A challenging digit by digit manipulation, rotate the digit in range of 0 to 9 laucn Excel Programming 14 05-17-2015 12:12 PM
How to populate cells in Sheet2 with Data Source query using cell data from Sheet1 bobznkazoo Excel 2 03-27-2014 11:14 AM
data manipulation Text manipulation in MACRO srt Word VBA 25 03-13-2013 03:25 PM
data manipulation Combobox manipulation vsempoux Word VBA 3 10-31-2009 08:58 AM
Mail merge Field Code Manipulation macjnr Mail Merge 0 09-10-2009 11:37 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 06:19 PM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2025, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2025 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft