Home |
Search |
Today's Posts |
#1
![]()
Posted to microsoft.public.excel.misc
|
|||
|
|||
![]()
I have huge sheet with thousands of non-standard lines of text. Some of the
lines have the following line in a cell: ProjID=MFG-Company-DA-33 ProjType=BBAA Uplift=0 CostType=Time Mgr=Smith I would like to understand how to write the VBA that will skip the lines that don't match this format and then Break out the items that do. This is what I have so far. some sort of loop statement here If activecell.value (left(5))="projID" then ' this is where a need the help. I want to move everything after ProjID= to Type= to the next column then move everything after Type= to Uplift= to a column 2 columns away and so on for the rest of the line. else activecell.offset (-1,0) loop End if Thanks for the help. I would use text to columns, but only few of the cells follow the format listed above. Thanks |
#2
![]()
Posted to microsoft.public.excel.misc
|
|||
|
|||
![]()
Use Autofilter to check the left side of the string. It should be
faster than looping through all the cells. PB |
#3
![]()
Posted to microsoft.public.excel.misc
|
|||
|
|||
![]() PB, Thanks for the reply. I'm trying to automate this so I change the value of those cells and leave the cells that do not fit the format are not changed. If I autofilter and then do the text to columns, it would still affect the non conforming cells. Any advise? Thanks in advance. B |
#4
![]()
Posted to microsoft.public.excel.misc
|
|||
|
|||
![]()
On Fri, 14 Mar 2008 11:24:00 -0700, Brennan
wrote: I have huge sheet with thousands of non-standard lines of text. Some of the lines have the following line in a cell: ProjID=MFG-Company-DA-33 ProjType=BBAA Uplift=0 CostType=Time Mgr=Smith I would like to understand how to write the VBA that will skip the lines that don't match this format and then Break out the items that do. This is what I have so far. some sort of loop statement here If activecell.value (left(5))="projID" then ' this is where a need the help. I want to move everything after ProjID= to Type= to the next column then move everything after Type= to Uplift= to a column 2 columns away and so on for the rest of the line. else activecell.offset (-1,0) loop End if Thanks for the help. I would use text to columns, but only few of the cells follow the format listed above. Thanks You haven't specifically defined your format, and I'm not clear if you want the label to be extracted also, but I made these assumptions to attract the various segments: Each segment to be extracted is preceded by a specific ?????= and followed by a <space. The ?????= labels all occur in the order given, and there are five of them in each relevant line. If the pattern doesn't match, extract nothing. That being the case, the macro below will extract the relevant data, from lines that match the format above: ======================================== Option Explicit Sub SplitSome() Dim rg As Range Dim c As Range Dim i As Long 'set up the range to process 'can be done in a variety of ways 'below assumes the range is contiguous 'and in one column Set rg = Selection(1, 1) Set rg = Range(rg.End(xlUp), rg.End(xlDown)) 'set up pattern for regex engine Dim re As Object, mc As Object Dim Str As String Set re = CreateObject("vbscript.regexp") re.Global = True re.Pattern = "ProjID=(.*?)\s+ProjType=(.*?)\s+Uplift=(.*)\s+Cos tType=(.*?)\s+Mgr=(.*)\s*" 'check all lines For Each c In rg Str = c.Value 'if the pattern doesn't match, will return nothing If re.test(Str) = True Then Set mc = re.Execute(Str) 'there must be five segments For i = 1 To 5 c.Offset(0, i * 2).Value = mc(0).submatches(i - 1) Next i End If Next c End Sub ========================================= --ron |
#5
![]()
Posted to microsoft.public.excel.misc
|
|||
|
|||
![]()
Outstanding - thank you. Very helpful!
b |
#6
![]()
Posted to microsoft.public.excel.misc
|
|||
|
|||
![]() "Brennan" wrote in message ... Outstanding - thank you. Very helpful! I am constantly amazed at the knowledge of the people here. I consider myself to be an adept intermediate Excel user - but sometimes I don't even understand the questions asked here never mind the solutions :-) |
#7
![]()
Posted to microsoft.public.excel.misc
|
|||
|
|||
![]()
On Fri, 14 Mar 2008 12:47:03 -0700, Brennan
wrote: Outstanding - thank you. Very helpful! b Glad to help. Let me know if it requires any "tweaking". --ron |
#8
![]()
Posted to microsoft.public.excel.misc
|
|||
|
|||
![]()
On Fri, 14 Mar 2008 20:07:57 GMT, "gavin"
wrote: "Brennan" wrote in message ... Outstanding - thank you. Very helpful! I am constantly amazed at the knowledge of the people here. I consider myself to be an adept intermediate Excel user - but sometimes I don't even understand the questions asked here never mind the solutions :-) Me too. And sometimes it can be very tough to figure out the question. --ron |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
How can I split contents of cell with no delimiter | Excel Discussion (Misc queries) | |||
Excel 2000 - Split Contents of Cell Across Multiple Cells | Excel Discussion (Misc queries) | |||
Split contents of a cell | Excel Worksheet Functions | |||
Can unmerged cell contents be split to another cell | Excel Worksheet Functions | |||
How to split the contents of a cell between two cells. | Excel Worksheet Functions |