Add Formula to macro to match with adjacent column

tropics123

Board Regular
Joined
May 11, 2016
Messages
85
Hello, thank you in advance for your help. I'm trying to add a formula to cell B2 (and going all the way down to match the number of rows in column A) to search for the "L0" in column A and replace both digits before "L0" with another "L0". Example, if the two digits before "L0" is "04", then replace the "04" with "L0".

The formula works fine on a regular excel sheet, however, when I add it as a VBA, the "L0" is creating a problem and macro won't run. Please help!

1) Column A (approximately 1000 lines looking like this with various digits before "L0". In this case it's "04" but it could be "73"). All this data could change with new files we receive:
[TABLE="width: 590"]
<tbody>[TR]
[TD="width: 590"]0012391235064899100012311804L01+00005254.00+0000000.000000+00000000.00+000000.00[/TD]
[/TR]
</tbody>[/TABLE]

2) Here's my VBA code:

Sub AddFormula()
'
Dim LastRowColumnA As Long

LastRowColumnA = Cells(Rows.Count, 1).End(xlUp).Row
Range("B2:B" & LastRowColumnA).Formula = "=IFERROR((REPLACE(A2,(SEARCH("L0",A2)-2),2,"L0")),"")"




End Sub
 

Excel Facts

Save Often
If you start asking yourself if now is a good time to save your Excel workbook, the answer is Yes
You need to double-up on the quotes inside the formula like
"=IFERROR((REPLACE(A2,(SEARCH(""L0"",A2)-2),2,""L0"")),"""")"
 
Upvote 0
Anything inside quotes is a string, so without the extra quotes "=IFERROR((REPLACE(A2,(SEARCH("L0",A2)-2),2,"L0")),"")" the parts in red would be treated as separate strings & the two L0 would be treated as variables.
 
Upvote 0

Forum statistics

Threads
1,225,315
Messages
6,184,234
Members
453,223
Latest member
Ignition04

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