VBA to transpose dataset and add a piece of data

wholly

New Member
Joined
Feb 18, 2013
Messages
16
Need to write vba code to sort of transpose from a horizontal data set to a vertical data set with an extra piece of data created.

If the table 1 has no data for mon -> sun just skip

Is there an easy way.. I just seem to be way our of my depth here!!

This data set has like 10,000 centres, so doing it by hand will take forever!!!

Thanks in advance



TABLE 1 - Original

ServiceApprovalNumberRatingsIssuedLast Service Approval Transfer DateAnnual Monday Start TimeAnnual Monday End TimeAnnual Tuesday Start TimeAnnual Tuesday End TimeAnnual Wednesday Start TimeAnnual Wednesday End TimeAnnual Thursday Start TimeAnnual Thursday End TimeAnnual Friday Start TimeAnnual Friday End Timelisting_id
SE-00009863Jul-16########6:3018:306:3018:306:3018:306:3018:306:3018:30155
SE-00009865Jun-14########7.4517.457.4517.457.4517.457.4517.457.4517.45255
New Sheet - TABLE 2
ServiceApprovalNumber listing_iddayopen_time close_timewhere day
SE-0000986315506:3018:300 = Monday
SE-0000986415516:3018:301 = Tuesday
SE-0000986515526:3018:302 = Wednesday
SE-0000986615536:3018:30
SE-0000986715546:3018:30skip if no hours data
SE-0000986525507.4517.45
SE-0000986625517.4517.45
SE-0000986725527.4517.45
SE-0000986825537.4517.45
SE-0000986925547.4517.45

<colgroup><col><col span="2"><col><col span="10"></colgroup><tbody>
</tbody>
 

Excel Facts

Round to nearest half hour?
Use =MROUND(A2,"0:30") to round to nearest half hour. Use =CEILING(A2,"0:30") to round to next half hour.
BTW.. I am using your 1st script as all the numbers within the code are time formatted.

Please use the code in Post #3 .

Please re-state what you're trying to say in post #'s 11,12 and 13. It's not at all clear to me.
 
Upvote 0
sorry for the delay Tonyyy

1. Updated script to Post#3

Error message is Runtime Error 9, subscript out of range

Posted pics below

Images not showing??? dont know why!

links are www.sweetsorella.com/excel1.jpg
www.sweetsorella.com/excel2.jpg

arr2(i, 1) = subscript out of range

thanks wayne

excel1.jpg

excel2.jpg
excel1.jpg
 
Last edited:
Upvote 0
Try replacing this line...

Code:
arr1 = Sheets(1).UsedRange

with...

Code:
arr1 = Sheets("Sheet1").UsedRange.Value
And as before, replace "Sheet1" with your own worksheet name.

And if you want a little better performance from the code, add the following line just below the Dim statements...

Code:
Application.ScreenUpdating = False
 
Upvote 0
Tonyyy

You bloody legend!!!!

Thank YOU!!!!

It works perfectly

Thanks you for your continual updates in helping me...

wayne
 
Upvote 0

Forum statistics

Threads
1,214,644
Messages
6,120,709
Members
448,983
Latest member
Joaquim_Baptista

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