filtering raw data

aphexcloud

New Member
Joined
Jul 20, 2011
Messages
10
Hi all
I have tryed searching for what i want but am unable to find what im looking for(noob to excell so i may have found the post and gorne straight past it) so thank you all in advance

my question is i have a raw data file that gets exported to excell and i am wanting to write a macro that will find a label number that has been picked up and place it next to the delivery row(whis will have the same label number)
my problem is that not all deliverys have been scaned and do not have any infomation on it so i want it to leave a blank row where there is no info for delivery so that at the end of the report all numbers corraspond

regards
andreas

ps:please forgive my horrible grammer and spelling :-?
 

Excel Facts

Remove leading & trailing spaces
Save as CSV to remove all leading and trailing spaces. It is faster than using TRIM().
aphexcloud,

Welcome to the MrExcel forum.

What version of Excel are you using?

You will generally get much more help (and faster) in this forum if you can post your small samples (what you have and what you expect to achieve) directly in the forum.

To attach screenshots, see below in my Signature block: Post a screen shot with one of these:
 
Upvote 0
thanks for the response i am using office 2010 to do all my work i have made the screen shots in office 2007 but the screen shots is just a example

here is what i would get as raw data but bout 9000 lines per report
and there may be 8500that match but at the end nothing collates


and i want to have a blank row where there is no corresponding label number
for delivery
 
Last edited:
Upvote 0
well a second edit so far i can not get the mrexcell html addin to work all it gives me is f 20......


so here goes excel genie
Sheet1


<TABLE style="BACKGROUND-COLOR: #ffffff; PADDING-LEFT: 2pt; PADDING-RIGHT: 2pt; FONT-FAMILY: Calibri,Arial; FONT-SIZE: 11pt" border=1 cellSpacing=0 cellPadding=0><COLGROUP><COL style="WIDTH: 30px; FONT-WEIGHT: bold"><COL style="WIDTH: 107px"><COL style="WIDTH: 64px"><COL style="WIDTH: 68px"><COL style="WIDTH: 141px"><COL style="WIDTH: 68px"><COL style="WIDTH: 87px"><COL style="WIDTH: 64px"></COLGROUP><TBODY><TR style="TEXT-ALIGN: center; BACKGROUND-COLOR: #cacaca; FONT-SIZE: 8pt; FONT-WEIGHT: bold"><TD> </TD><TD>A</TD><TD>B</TD><TD>C</TD><TD>D</TD><TD>E</TD><TD>F</TD><TD>G</TD></TR><TR style="HEIGHT: 18px"><TD style="TEXT-ALIGN: center; BACKGROUND-COLOR: #cacaca; FONT-SIZE: 8pt">1</TD><TD>label</TD><TD>del type</TD><TD>date </TD><TD>label</TD><TD>del type </TD><TD>date</TD><TD> </TD></TR><TR style="HEIGHT: 18px"><TD style="TEXT-ALIGN: center; BACKGROUND-COLOR: #cacaca; FONT-SIZE: 8pt">2</TD><TD>ml00001234</TD><TD>pickup</TD><TD style="TEXT-ALIGN: right">1/07/2011</TD><TD>ml00001234</TD><TD>delivery</TD><TD style="TEXT-ALIGN: right">2/07/2011</TD><TD> </TD></TR><TR style="HEIGHT: 18px"><TD style="TEXT-ALIGN: center; BACKGROUND-COLOR: #cacaca; FONT-SIZE: 8pt">3</TD><TD>ml00001235</TD><TD>pickup</TD><TD style="TEXT-ALIGN: right">2/07/2011</TD><TD>ml00001235</TD><TD>delivery</TD><TD style="TEXT-ALIGN: right">4/07/2011</TD><TD>raw</TD></TR><TR style="HEIGHT: 18px"><TD style="TEXT-ALIGN: center; BACKGROUND-COLOR: #cacaca; FONT-SIZE: 8pt">4</TD><TD>ml00001236</TD><TD>pickup</TD><TD style="TEXT-ALIGN: right">3/07/2011</TD><TD>ml00001237</TD><TD>delivery</TD><TD style="TEXT-ALIGN: right">5/07/2011</TD><TD> </TD></TR><TR style="HEIGHT: 18px"><TD style="TEXT-ALIGN: center; BACKGROUND-COLOR: #cacaca; FONT-SIZE: 8pt">5</TD><TD>ml00001237</TD><TD>pickup</TD><TD style="TEXT-ALIGN: right">4/07/2011</TD><TD> </TD><TD> </TD><TD> </TD><TD> </TD></TR><TR style="HEIGHT: 18px"><TD style="TEXT-ALIGN: center; BACKGROUND-COLOR: #cacaca; FONT-SIZE: 8pt">6</TD><TD> </TD><TD> </TD><TD> </TD><TD> </TD><TD> </TD><TD> </TD><TD> </TD></TR><TR style="HEIGHT: 18px"><TD style="TEXT-ALIGN: center; BACKGROUND-COLOR: #cacaca; FONT-SIZE: 8pt">7</TD><TD> </TD><TD> </TD><TD> </TD><TD> </TD><TD> </TD><TD> </TD><TD> </TD></TR><TR style="HEIGHT: 18px"><TD style="TEXT-ALIGN: center; BACKGROUND-COLOR: #cacaca; FONT-SIZE: 8pt">8</TD><TD>label</TD><TD>del type</TD><TD>date </TD><TD>label</TD><TD>del type </TD><TD>date</TD><TD> </TD></TR><TR style="HEIGHT: 18px"><TD style="TEXT-ALIGN: center; BACKGROUND-COLOR: #cacaca; FONT-SIZE: 8pt">9</TD><TD>ml00001234</TD><TD>pickup</TD><TD style="TEXT-ALIGN: right">1/07/2011</TD><TD>ml00001234</TD><TD>delivery</TD><TD style="TEXT-ALIGN: right">2/07/2011</TD><TD> </TD></TR><TR style="HEIGHT: 18px"><TD style="TEXT-ALIGN: center; BACKGROUND-COLOR: #cacaca; FONT-SIZE: 8pt">10</TD><TD>ml00001235</TD><TD>pickup</TD><TD style="TEXT-ALIGN: right">2/07/2011</TD><TD>ml00001235</TD><TD>delivery</TD><TD style="TEXT-ALIGN: right">4/07/2011</TD><TD>collated</TD></TR><TR style="HEIGHT: 18px"><TD style="TEXT-ALIGN: center; BACKGROUND-COLOR: #cacaca; FONT-SIZE: 8pt">11</TD><TD>ml00001236</TD><TD>pickup</TD><TD style="TEXT-ALIGN: right">3/07/2011</TD><TD> </TD><TD> </TD><TD> </TD><TD> </TD></TR><TR style="HEIGHT: 18px"><TD style="TEXT-ALIGN: center; BACKGROUND-COLOR: #cacaca; FONT-SIZE: 8pt">12</TD><TD>ml00001237</TD><TD>pickup</TD><TD style="TEXT-ALIGN: right">4/07/2011</TD><TD>ml00001237</TD><TD>delivery</TD><TD style="TEXT-ALIGN: right">5/07/2011</TD><TD> </TD></TR></TBODY></TABLE>


Excel tables to the web >> http://www.excel-jeanie-html.de/index.php?f=1" target="_blank"> Excel Jeanie HTML 4

yay it works
 
Last edited:
Upvote 0
aphexcloud,


Sample raw data in worksheet Sheet1:


Excel Workbook
ABCDEF
1labeldel typedatelabeldel typedate
2ml00001234pickup1/7/2011ml00001234delivery2/7/2011
3ml00001235pickup2/7/2011ml00001235delivery4/7/2011
4ml00001236pickup3/7/2011ml00001237delivery5/7/2011
5ml00001237pickup4/7/2011
6
Sheet1





After the macro:


Excel Workbook
ABCDEF
1labeldel typedatelabeldel typedate
2ml00001234pickup1/7/2011ml00001234delivery2/7/2011
3ml00001235pickup2/7/2011ml00001235delivery4/7/2011
4ml00001236pickup3/7/2011
5ml00001237pickup4/7/2011ml00001237delivery5/7/2011
6
Sheet1





Please TEST this FIRST in a COPY of your workbook (always make a backup copy before trying new code, you never know what you might lose).


1. Copy the below code, by highlighting the code and pressing the keys CTRL + C
2. Open your workbook
3. Press the keys ALT + F11 to open the Visual Basic Editor
4. Press the keys ALT + I to activate the Insert menu
5. Press M to insert a Standard Module
6. Where the cursor is flashing, paste the code by pressing the keys CTRL + V
7. Press the keys ALT + Q to exit the Editor, and return to Excel
8. To run the macro from Excel, open the workbook, and press ALT + F8 to display the Run Macro Dialog. Double Click the macro's name to Run it.


Code:
Option Explicit
Sub AlignLabel()
' hiker95, 07/21/2011
' http://www.mrexcel.com/forum/showthread.php?t=565822
' The macro was modified from code by:
' Krishnakumar, 12/12/2010
' http://www.ozgrid.com/forum/showthread.php?t=148881
Dim ws As Worksheet
Dim LR As Long, a As Long
Dim Label As Range
Application.ScreenUpdating = False
Set ws = Worksheets("Sheet1")
LR = ws.Range("A" & ws.Rows.Count).End(xlUp).Row
ws.Range("A2:C" & LR).Sort Key1:=ws.Range("A2"), Order1:=xlAscending, Header:=xlNo, _
  OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom, DataOption1:=xlSortNormal
LR = ws.Range("D" & ws.Rows.Count).End(xlUp).Row
ws.Range("D2:D" & LR).Sort Key1:=ws.Range("D2"), Order1:=xlAscending, Header:=xlNo, _
  OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom, DataOption1:=xlSortNormal
Set Label = ws.Range("A2:C" & LR)
a = 2
Do While Label.Cells(a, 1) <> ""
  If Label.Cells(a, 1).Offset(, 3) <> "" Then
    If Label.Cells(a, 1) < Label.Cells(a, 1).Offset(, 3) Then
      Label.Cells(a, 1).Offset(, 3).Resize(, 3).Insert -4121
    ElseIf Label.Cells(a, 1) > Label.Cells(a, 1).Offset(, 3) Then
      Label.Cells(a, 1).Resize(, 3).Insert -4121
      LR = LR + 1
      Set Label = ws.Range("A2:C" & LR)
    End If
  End If
  a = a + 1
Loop
Application.ScreenUpdating = 1
End Sub


Before you use the macro with Excel 2007 or newer, save your workbook, Save As, a macro enabled workbook with the file extension .xlsm


Then run the AlignLabel macro.
 
Upvote 0
aphexcloud,

The macro did not work on your actual data because the structure is not the same. You have gone from 3 columns by 3, to 6 columns by 6 columns.


Sample NEW raw data in worksheet Sheet1 before the macro:


Excel Workbook
ABCDEFGHIJKL
1LabelActionScan DateScan TimeRun DescriptionCapturedLabelActionScan DateScan TimeRun DescriptionCaptured
2RBAML2519224Pickup1/06/11 12:24:1112:24:11Dandenong North1/06/11 11:25:51RBAML2519151Delivery1/06/11 8:18:0208:18:02Preston1/06/11 9:35:37
3RBATR0079759Pickup1/06/11 12:24:1112:24:11Dandenong North1/06/11 11:25:51RBAML2519152Delivery1/06/11 8:18:0208:18:02Preston1/06/11 9:35:37
4RBAML2519204Pickup1/06/11 12:24:1112:24:11Dandenong North1/06/11 11:25:51RBATR0079679Delivery1/06/11 8:18:0208:18:02Preston1/06/11 9:35:37
5RBAML2519205Pickup1/06/11 12:24:1112:24:11Dandenong North1/06/11 11:25:51RBAML2519146Delivery1/06/11 9:06:4209:06:42Dandenong North1/06/11 8:07:08
6RBAML2519196Pickup1/06/11 12:24:1112:24:11Dandenong North1/06/11 11:25:51RBAML2519150Delivery1/06/11 9:15:3109:15:31Preston1/06/11 10:33:23
7RBAML2519194Pickup1/06/11 12:24:1112:24:11Dandenong North1/06/11 11:25:51RBAML1909546Delivery1/06/11 9:21:1909:21:19Laverton1/06/11 8:21:45
8RBAML2519195Pickup1/06/11 12:24:1112:24:11Dandenong North1/06/11 11:25:51RBAML1909553Delivery1/06/11 9:21:1909:21:19Laverton1/06/11 8:21:45
9RBATR0079756Pickup1/06/11 12:24:1112:24:11Dandenong North1/06/11 11:25:51RBAML2519173Delivery1/06/11 9:32:2809:32:28Ferntree Gully1/06/11 8:32:48
10RBAML2519203Pickup1/06/11 12:24:1112:24:11Dandenong North1/06/11 11:25:51RBAML2519111Delivery1/06/11 9:38:0609:38:06Dandenong North1/06/11 8:38:21
11RBATR0079763Pickup1/06/11 12:24:1112:24:11Dandenong North1/06/11 11:25:51RBAML2519127Delivery1/06/11 9:45:1109:45:11Laverton1/06/11 8:45:53
12RBAML2519225Pickup1/06/11 12:24:1112:24:11Dandenong North1/06/11 11:25:51RBAML2519126Delivery1/06/11 9:45:1109:45:11Laverton1/06/11 8:45:53
13RBATR0079762Pickup1/06/11 12:24:1112:24:11Dandenong North1/06/11 11:25:51RBATR0079639Delivery1/06/11 9:45:1109:45:11Laverton1/06/11 8:45:53
14RBAML2519219Pickup1/06/11 12:24:1112:24:11Dandenong North1/06/11 11:25:51RBATR0079638Delivery1/06/11 9:45:1109:45:11Laverton1/06/11 8:45:53
15RBAML2519220Pickup1/06/11 12:24:1112:24:11Dandenong North1/06/11 11:25:51RBAML1909563Delivery1/06/11 9:45:1109:45:11Laverton1/06/11 8:45:53
16RBATR0079774Pickup1/06/11 12:24:1112:24:11Dandenong North1/06/11 11:25:51RBAML1909551Delivery1/06/11 9:45:1109:45:11Laverton1/06/11 8:45:53
17RBATR0079775Pickup1/06/11 12:24:1112:24:11Dandenong North1/06/11 11:25:51RBAML2519168Delivery1/06/11 9:46:5109:46:51Bayswater1/06/11 8:47:23
18RBAVL2519218Pickup1/06/11 12:24:1112:24:11Dandenong North1/06/11 11:25:51RBAML2519155Delivery1/06/11 9:46:5109:46:51Bayswater1/06/11 8:47:23
19RBAVL2519217Pickup1/06/11 12:24:1112:24:11Dandenong North1/06/11 11:25:51RBATR0079723Delivery1/06/11 9:46:5109:46:51Bayswater1/06/11 8:47:23
20RBAML2519215Pickup1/06/11 12:24:1112:24:11Dandenong North1/06/11 11:25:51RBATR0079722Delivery1/06/11 9:46:5109:46:51Bayswater1/06/11 8:47:23
21RBAML2519216Pickup1/06/11 12:24:1112:24:11Dandenong North1/06/11 11:25:51RBAML1909556Delivery1/06/11 9:46:5109:46:51Bayswater1/06/11 8:47:23
22RBATR0079758Pickup1/06/11 12:24:1112:24:11Dandenong North1/06/11 11:25:51RBAML2519175Delivery1/06/11 9:46:5109:46:51Bayswater1/06/11 8:47:23
23RBAML2519206Pickup1/06/11 12:24:1112:24:11Dandenong North1/06/11 11:25:51RBAML2519176Delivery1/06/11 9:46:5109:46:51Bayswater1/06/11 8:47:23
24RBAML2519207Pickup1/06/11 12:24:1112:24:11Dandenong North1/06/11 11:25:51RBAML1601978Delivery1/06/11 9:50:0909:50:09Notting Hill1/06/11 8:50:24
25RBATR0079753Pickup1/06/11 12:24:1112:24:11Dandenong North1/06/11 11:25:51RBAML1601979Delivery1/06/11 9:50:0909:50:09Notting Hill1/06/11 8:50:24
Sheet1





After the updated macro:


Excel Workbook
ABCDEFGHIJKL
1LabelActionScan DateScan TimeRun DescriptionCapturedLabelActionScan DateScan TimeRun DescriptionCaptured
2RBAML1104484Pickup8/06/11 17:31:0017:31:00Dandenong North8/06/11 16:32:43RBAML1104484Delivery9/06/11 11:57:4011:57:40Mentone9/06/11 10:58:06
3RBAML1104485Pickup8/06/11 17:31:0017:31:00Dandenong North8/06/11 16:32:43RBAML1104485Delivery9/06/11 12:05:5112:05:51Northcote9/06/11 11:06:10
4RBAML1104486Pickup8/06/11 17:31:0017:31:00Dandenong North8/06/11 16:32:43RBAML1104486Delivery9/06/11 15:52:3815:52:38Dandenong North9/06/11 14:53:09
5RBAML1104487Pickup14/06/11 12:38:2712:38:27Berwick14/06/11 11:39:49RBAML1104487Delivery15/06/11 7:43:4107:43:41Coburg North15/06/11 7:43:54
6RBAML1104488Pickup15/06/11 12:51:5512:51:55Berwick15/06/11 11:53:32RBAML1104488Delivery16/06/11 11:12:4111:12:41Bentleigh16/06/11 10:13:09
7RBAML1104489Pickup16/06/11 12:25:5012:25:50Dandenong North16/06/11 11:27:08RBAML1104489Delivery16/06/11 15:26:5215:26:52Glen Waverley16/06/11 14:27:18
8RBAML1104490Pickup16/06/11 12:25:5012:25:50Dandenong North16/06/11 11:27:08RBAML1104490Delivery20/06/11 12:30:0912:30:09Frankston20/06/11 11:30:36
9RBAML1104491Pickup16/06/11 12:25:5012:25:50Dandenong North16/06/11 11:27:08RBAML1104491Delivery17/06/11 10:57:5310:57:53Berwick17/06/11 9:58:09
10RBAML1104493Pickup16/06/11 12:25:5012:25:50Dandenong North16/06/11 11:27:08RBAML1104493Delivery20/06/11 11:21:5011:21:50Berwick20/06/11 10:22:10
11RBAML1104495Pickup17/06/11 12:29:5812:29:58Dandenong North17/06/11 11:31:21RBAML1104495Delivery17/06/11 15:52:3015:52:30Thomastown17/06/11 14:52:59
12RBAML1104496Pickup23/06/11 12:24:5912:24:59Berwick23/06/11 11:26:04RBAML1104496Delivery23/06/11 16:26:5416:26:54Notting Hill23/06/11 15:27:21
13RBAML1104497Pickup23/06/11 12:24:5912:24:59Berwick23/06/11 11:26:04RBAML1104497Delivery23/06/11 16:26:5416:26:54Notting Hill23/06/11 15:27:21
14RBAML1104498Pickup23/06/11 12:24:5912:24:59Berwick23/06/11 11:26:04RBAML1104498Delivery23/06/11 16:26:5416:26:54Notting Hill23/06/11 15:27:21
15RBAML1516723Pickup2/06/11 17:46:0017:46:00Dandenong North2/06/11 16:47:37RBAML1516723Delivery3/06/11 15:42:5015:42:50Heidelberg3/06/11 14:43:24
16RBAML1516724Pickup6/06/11 12:40:2912:40:29Dandenong North6/06/11 11:42:04
17RBAML1516725Pickup6/06/11 12:40:2912:40:29Dandenong North6/06/11 11:42:03
18RBAML1516726Pickup6/06/11 12:40:2912:40:29Dandenong North6/06/11 11:42:03
19RBAML1516727Pickup6/06/11 12:40:2912:40:29Dandenong North6/06/11 11:42:03
20RBAML1516728Delivery14/06/11 11:21:3511:21:35Bayswater North14/06/11 10:22:12
21RBAML1516729Delivery14/06/11 11:21:3511:21:35Bayswater North14/06/11 10:22:12
22RBAML1516730Delivery14/06/11 11:21:3511:21:35Bayswater North14/06/11 10:22:12
23RBAML1516731Pickup17/06/11 17:12:1417:12:14Dandenong North17/06/11 16:13:57RBAML1516731Delivery20/06/11 11:04:1311:04:13Star Depot20/06/11 10:05:35
24RBAML1516732Pickup17/06/11 17:12:1417:12:14Dandenong North17/06/11 16:13:57RBAML1516732Delivery20/06/11 11:04:1311:04:13Star Depot20/06/11 10:05:35
25RBAML1601914Delivery7/06/11 10:49:0710:49:07Notting Hill7/06/11 9:49:44
Sheet1





Please TEST this FIRST in a COPY of your workbook (always make a backup copy before trying new code, you never know what you might lose).


1. Copy the below code, by highlighting the code and pressing the keys CTRL + C
2. Open your workbook
3. Press the keys ALT + F11 to open the Visual Basic Editor
4. Press the keys ALT + I to activate the Insert menu
5. Press M to insert a Standard Module
6. Where the cursor is flashing, paste the code by pressing the keys CTRL + V
7. Press the keys ALT + Q to exit the Editor, and return to Excel
8. To run the macro from Excel, open the workbook, and press ALT + F8 to display the Run Macro Dialog. Double Click the macro's name to Run it.


Code:
Option Explicit
Sub AlignLabelV2()
' hiker95, 07/21/2011
' http://www.mrexcel.com/forum/showthread.php?t=565822
' The macro was modified from code by:
' Krishnakumar, 12/12/2010
' http://www.ozgrid.com/forum/showthread.php?t=148881
Dim ws As Worksheet
Dim LR As Long, a As Long
Dim Label As Range
Application.ScreenUpdating = False
Set ws = Worksheets("Sheet1")
LR = ws.Range("A" & ws.Rows.Count).End(xlUp).Row
ws.Range("A2:F" & LR).Sort Key1:=ws.Range("A2"), Order1:=xlAscending, Header:=xlNo, _
  OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom, DataOption1:=xlSortNormal
LR = ws.Range("G" & ws.Rows.Count).End(xlUp).Row
ws.Range("G2:L" & LR).Sort Key1:=ws.Range("G2"), Order1:=xlAscending, Header:=xlNo, _
  OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom, DataOption1:=xlSortNormal
Set Label = ws.Range("A2:F" & LR)
a = 2
Do While Label.Cells(a, 1) <> ""
  If Label.Cells(a, 1).Offset(, 6) <> "" Then
    If Label.Cells(a, 1) < Label.Cells(a, 1).Offset(, 6) Then
      Label.Cells(a, 1).Offset(, 6).Resize(, 6).Insert -4121
    ElseIf Label.Cells(a, 1) > Label.Cells(a, 1).Offset(, 6) Then
      Label.Cells(a, 1).Resize(, 6).Insert -4121
      LR = LR + 1
      Set Label = ws.Range("A2:F" & LR)
    End If
  End If
  a = a + 1
Loop
Application.ScreenUpdating = 1
End Sub


Before you use the macro with Excel 2007 or newer, save your workbook, Save As, a macro enabled workbook with the file extension .xlsm


Then run the AlignLabelV2 macro.
 
Upvote 0

Forum statistics

Threads
1,224,598
Messages
6,179,814
Members
452,945
Latest member
Bib195

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