Seeking help to format data with a macro

abberyfarm

Well-known Member
Joined
Aug 14, 2011
Messages
733
Hi there,

I was hoping somebody might be able to help me check and format some data with some code.

I have 100,000+ rows that look like this
Excel Workbook
ABCDEFG
1start_datestart_timeend_dateend_timeTypeSOC BeforeSOC After
208/01/201218:36:2008/01/201218:40:00T**
308/01/201218:45:1208/01/201218:50:44T**
408/01/201218:52:1208/01/201219:50:46C3446
508/01/201219:54:2708/01/201221:44:40C4681
608/01/201221:48:4108/01/201222:02:36C8187
708/01/201222:06:4608/01/201222:11:49C8787
808/01/201222:15:5008/01/201223:02:00C87100
909/01/201208:16:5109/01/201208:44:08T**
1009/01/201208:45:1109/01/201208:49:55T**
Sheet1





I'm trying to merge all the "C" types in Column E into one row like this
Excel Workbook
ABCDEFG
14start_datestart_timeend_dateend_timeTypeSOC BeforeSOC After
1508/01/201218:36:2008/01/201218:40:00T**
1608/01/201218:45:1208/01/201218:50:44T**
1708/01/201218:52:1208/01/201223:02:00C34100
1809/01/201208:16:5109/01/201208:44:08T**
1909/01/201208:45:1109/01/201208:49:55T**
Sheet1




So basically, I need to use the 'start date' and 'start time' from the first row and the 'start date' and 'start time' from the last row. Also use the first 'SOC before' and the last 'SOC' After'.

I have more data in column h - column z, so I need to delete the entire row of the additional "C" rows. Otherwise the data will be misaligned.

Appreciate any help with this

Thank you in advance

John
 

Excel Facts

Who is Mr Spreadsheet?
Author John Walkenbach was Mr Spreadsheet until his retirement in June 2019.
Try this:-
Code:
[COLOR="Navy"]Sub[/COLOR] MG28Jun07
[COLOR="Navy"]Dim[/COLOR] Rng     [COLOR="Navy"]As[/COLOR] Range
[COLOR="Navy"]Dim[/COLOR] Dn      [COLOR="Navy"]As[/COLOR] Range
[COLOR="Navy"]Dim[/COLOR] nRng    [COLOR="Navy"]As[/COLOR] Range
[COLOR="Navy"]Set[/COLOR] Rng = Range(Range("A1"), Range("A" & Rows.Count).End(xlUp))
[COLOR="Navy"]For[/COLOR] [COLOR="Navy"]Each[/COLOR] Dn [COLOR="Navy"]In[/COLOR] Rng
    [COLOR="Navy"]If[/COLOR] Dn.Offset(, 4) = "C" [COLOR="Navy"]Then[/COLOR]
        [COLOR="Navy"]If[/COLOR] nRng [COLOR="Navy"]Is[/COLOR] Nothing [COLOR="Navy"]Then[/COLOR]
            [COLOR="Navy"]Set[/COLOR] nRng = Dn
        [COLOR="Navy"]Else[/COLOR]
            [COLOR="Navy"]Set[/COLOR] nRng = Union(nRng, Dn)
        [COLOR="Navy"]End[/COLOR] If
[COLOR="Navy"]End[/COLOR] If
[COLOR="Navy"]Next[/COLOR] Dn
[COLOR="Navy"]If[/COLOR] Not nRng [COLOR="Navy"]Is[/COLOR] Nothing [COLOR="Navy"]Then[/COLOR]
    nRng(1).Offset(, 3) = nRng(nRng.Count).Offset(, 3)
    nRng(1).Offset(, 6) = nRng(nRng.Count).Offset(, 6)
    nRng.Offset(1).Resize(nRng.Count - 1).EntireRow.Delete
[COLOR="Navy"]End[/COLOR] [COLOR="Navy"]If[/COLOR]
[COLOR="Navy"]End[/COLOR] [COLOR="Navy"]Sub[/COLOR]
Regards Mick
 
Upvote 0
Does the '*' [e.g. in cell F2] mean real empty space [doesn't contain a formula which gives blank]?
 
Upvote 0

Forum statistics

Threads
1,203,565
Messages
6,056,102
Members
444,846
Latest member
pbailey

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