macro to output a string

diageminc

New Member
Joined
Apr 15, 2010
Messages
25
Hello,
ItemQtyOutput
P184562
P 18456 quantity 2
SP104581
SP 10458 quantity 1
SR10456-92SR 10456 dash 9 quantity 2
E89864E 8986 quantity 4

<tbody>
</tbody>

Please refer to the above table, we have the following formula to translate col A and Col B to the desired output
=REPLACE(SUBSTITUTE(A2,"-"," dash "),IF(ISNUMBER(VALUE((MID(A2,2,1)))),2,3),0," ")&" quantity "&B2

We are looking for a macro that can accomplish the same output instead of a formula.

Any ideas?

Thanks
Amit
 

Excel Facts

Enter current date or time
Ctrl+: enters current time. Ctrl+; enters current date. Use Ctrl+: Ctrl+; Enter for current date & time.
Give this macro a try...
Code:
[table="width: 500"]
[tr]
	[td]Sub ReplaceDashAffixQuantity()
  Dim LastRow As Long
  LastRow = Cells(Rows.Count, "A").End(xlUp).Row
  Range("C2:C" & LastRow) = Evaluate(Replace("IF(A2:A#="""","""",SUBSTITUTE(REPLACE(A2:A#,3-ISNUMBER(0+MID(A2:A#,2,1)),0,"" ""),""-"","" dash "")&"" quantity ""&B2:B#)", "#", LastRow))
End Sub[/td]
[/tr]
[/table]
 
Upvote 0
Give this macro a try...
Code:
[TABLE="width: 500"]
<tbody>[TR]
[TD]Sub ReplaceDashAffixQuantity()
  Dim LastRow As Long
  LastRow = Cells(Rows.Count, "A").End(xlUp).Row
  Range("C2:C" & LastRow) = Evaluate(Replace("IF(A2:A#="""","""",SUBSTITUTE(REPLACE(A2:A#,3-ISNUMBER(0+MID(A2:A#,2,1)),0,"" ""),""-"","" dash "")&"" quantity ""&B2:B#)", "#", LastRow))
End Sub[/TD]
[/TR]
</tbody>[/TABLE]
Thanks Rick,

this is perfect.

amit
 
Upvote 0

Forum statistics

Threads
1,216,179
Messages
6,129,332
Members
449,502
Latest member
TSH8125

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