LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,934
Default Parsing a text field to retrieve numeric values

Do you still have the mix of 2 and 4 number text as you posted in your
previous thread? I'll assume so. Here is the code I posted in your
original
thread, modified to handle the 4 number situation as you have now
described...

Sub MultiplyFirstTwoValues()
Dim X As Long, LastRow As Long, Numbers As Variant
LastRow = Cells(Rows.Count, "A").End(xlUp).Row
On Error Resume Next
For X = 1 To LastRow
Numbers = Split(Cells(X, "A").Value, "x", , vbTextCompare)
If UBound(Numbers) = 1 Then
Cells(X, "B").Value = Numbers(0) * Numbers(1)
Else
Cells(X, "B").Value = (Numbers(0) * Numbers(1)) + _
(Numbers(2) * Numbers(3))
End If
Next
End Sub


I know you're fond of one-liners:

Evaluate(WorksheetFunction.Substitute(Replace(s, "x", "*"), "*", "+", 2))


To Ron: Yes, I do... and that one looks good to me!

To u473: To implement this in a macro (as opposed to a UDF which Ron gave
you directly in his response to you), it would be done this way...

Sub MultiplyAddCellValues()
Dim X As Long
For X = 1 To Cells(Rows.Count, "A").End(xlUp).Row
Cells(X, "B").Value = Evaluate(WorksheetFunction.Substitute(Replace( _
Cells(X, "A").Value, "x", "*"), "*", "+", 2))
Next
End Sub

--
Rick (MVP - Excel)

 
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
Keep text out of numeric field Diane Setting up and Configuration of Excel 1 September 29th 09 05:50 AM
Formatting UserForm Text Field as Numeric Paul D. Simon Excel Programming 4 January 17th 08 12:19 PM
Parsing Last Character in variable length text field Traci Excel Worksheet Functions 3 October 4th 07 04:11 PM
how do i step thru a text field looking for 6 numeric characters Snookman150 Excel Worksheet Functions 0 June 30th 05 01:31 PM
parsing text field based on commas or spaces Excel User Excel Programming 1 October 22nd 04 09:34 PM


All times are GMT +1. The time now is 09:02 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"