Home |
Search |
Today's Posts |
|
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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) |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
Keep text out of numeric field | Setting up and Configuration of Excel | |||
Formatting UserForm Text Field as Numeric | Excel Programming | |||
Parsing Last Character in variable length text field | Excel Worksheet Functions | |||
how do i step thru a text field looking for 6 numeric characters | Excel Worksheet Functions | |||
parsing text field based on commas or spaces | Excel Programming |