LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #8   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 226
Default Add comma after last " in a cell

ok.

--


Gary Keramidas
Excel 2003


"Ron Rosenfeld" wrote in message
...
On Sat, 22 May 2010 14:55:33 -0400, "Gary Keramidas"
wrote:

ron:

would something like this be simpler than using regex? i know it's
powerful,
but i have a hard time understanding it.

just wondering

Sub test()
Dim lastQt As Long
Dim lastrow As Long
Dim ws As Worksheet
Dim cell As Range
Set ws = Worksheets("Sheet1")
lastrow = ws.Cells(Rows.Count, "A").End(xlUp).Row

For Each cell In ws.Range("A1:A" & lastrow)
lastQt = InStrRev(cell.Value, """")
If lastQt 0 Then
cell.Offset(, 1).Value = Trim(Left(cell.Value, lastQt))
cell.Offset(, 2).Value = Trim(Right(cell.Value, Len(cell.Value) _
- lastQt))
End If
Next
End Sub


Your approach would probably run faster. But "simpler" is in the eye of
the
beholder. It's pretty simple for me to devise and test a regex, so I save
"development" time. Especially if the initially given parameters are
incomplete, as is frequently the case, and require modifications.

For example, we don't know how the OP wants to handle entries that do NOT
have
measurements. I chose to put the non-measurement part in the same column
as
the other part descriptions; you ignore it; p45cal has it in the
measurements
column.

For me to change the treatment of that instance requires only a small
change in
the regex pattern.

By the way, given the OP's requirements, your lastQt line should probably
be:

lastQt = WorksheetFunction.Max(InStrRev(cell.Value, """"), _
InStrRev(cell.Value, "'"))

--ron


 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
How can I center a number in "comma" format? Eric Excel Discussion (Misc queries) 8 April 2nd 23 07:10 PM
excel 2003: how do I fix: "Style 'Comma' not found" jrp9206 Excel Worksheet Functions 4 March 25th 16 07:09 AM
syntax for "IF" commend to check for multiple empty cells bf comma Chris Excel Worksheet Functions 4 September 3rd 07 12:02 PM
Interpreting "comma" where an optional argument is Epinn Excel Worksheet Functions 4 January 17th 07 12:04 AM
no comma separator for ="total"&"$ "&sum(a1:a10) Jeff Excel Worksheet Functions 3 August 9th 06 05:06 PM


All times are GMT +1. The time now is 09:13 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"