macro to output a string

diageminc

New Member
Joined
Apr 15, 2010
Messages
25
Hello,
[TABLE="width: 500"]
<tbody>[TR]
[TD]Item[/TD]
[TD]Qty[/TD]
[TD][/TD]
[TD]Output[/TD]
[/TR]
[TR]
[TD]P18456[/TD]
[TD]2
[/TD]
[TD][/TD]
[TD]P 18456 quantity 2[/TD]
[/TR]
[TR]
[TD]SP10458[/TD]
[TD]1
[/TD]
[TD][/TD]
[TD]SP 10458 quantity 1[/TD]
[/TR]
[TR]
[TD]SR10456-9[/TD]
[TD]2[/TD]
[TD][/TD]
[TD]SR 10456 dash 9 quantity 2[/TD]
[/TR]
[TR]
[TD]E8986[/TD]
[TD]4[/TD]
[TD][/TD]
[TD]E 8986 quantity 4[/TD]
[/TR]
</tbody>[/TABLE]

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

Which lookup functions find a value equal or greater than the lookup value?
MATCH uses -1 to find larger value (lookup table must be sorted ZA). XLOOKUP uses 1 to find values greater and does not need to be sorted.
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,223,996
Messages
6,175,853
Members
452,675
Latest member
duongtruc1610

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