reubanrao93
New Member
- Joined
- Dec 7, 2020
- Messages
- 20
- Office Version
- 365
- Platform
- Windows
Hi guys, I'm trying to insert a formula in my code which works in the sheet but not in vba. Running the code below returns a syntax error. I noticed that the errors are due to SEARCH strings containing paratheses for "ENO=" and ",SUB". I've tried changing the paratheses to CHR(34) as well but now it returns run-time error 1004 instead. Is there something I'm missing here?
*ORIGINAL*
Sub PastFormula()
Dim LRw As Long
Sheets("Sheet1").Range("S:S").Select
ActiveCell.Formula = "=MID(L2,(LEN(L2)-(LEN(LEFT(L2,LEN(L2)-SEARCH(“ENO=“,L2)))-4)),((LEN(LEFT(L2,LEN(L2)-SEARCH(“ENO=“,L2)))-4)-(LEN(LEFT(L2,LEN(L2)-SEARCH(“,SUB”,L2))))))"
LRw = Range ("L" & Rows.Count).End(xlUp).Row
Range(ActiveCell, Cells(LRw, ActiveCell.Column)).FillDown
End Sub
*Parantheses changed into CHR(34)*
Sub PastFormula()
Dim LRw As Long
Sheets("Sheet1").Range("S:S").Select
ActiveCell.Formula = "=MID(L2,(LEN(L2)-(LEN(LEFT(L2,LEN(L2)-SEARCH(CHR(34)&ENO=&CHR(34),L2)))-4)),((LEN(LEFT(L2,LEN(L2)-SEARCH(CHR(34)&ENO=&CHR(34),L2)))-4)-(LEN(LEFT(L2,LEN(L2)-SEARCH(CHR(34)&,SUB&CHR(34),L2))))))"
LRw = Range("L" & Rows.Count).End(xlUp).Row
Range(ActiveCell, Cells(LRw, ActiveCell.Column)).FillDown
End Sub
*ORIGINAL*
Sub PastFormula()
Dim LRw As Long
Sheets("Sheet1").Range("S:S").Select
ActiveCell.Formula = "=MID(L2,(LEN(L2)-(LEN(LEFT(L2,LEN(L2)-SEARCH(“ENO=“,L2)))-4)),((LEN(LEFT(L2,LEN(L2)-SEARCH(“ENO=“,L2)))-4)-(LEN(LEFT(L2,LEN(L2)-SEARCH(“,SUB”,L2))))))"
LRw = Range ("L" & Rows.Count).End(xlUp).Row
Range(ActiveCell, Cells(LRw, ActiveCell.Column)).FillDown
End Sub
*Parantheses changed into CHR(34)*
Sub PastFormula()
Dim LRw As Long
Sheets("Sheet1").Range("S:S").Select
ActiveCell.Formula = "=MID(L2,(LEN(L2)-(LEN(LEFT(L2,LEN(L2)-SEARCH(CHR(34)&ENO=&CHR(34),L2)))-4)),((LEN(LEFT(L2,LEN(L2)-SEARCH(CHR(34)&ENO=&CHR(34),L2)))-4)-(LEN(LEFT(L2,LEN(L2)-SEARCH(CHR(34)&,SUB&CHR(34),L2))))))"
LRw = Range("L" & Rows.Count).End(xlUp).Row
Range(ActiveCell, Cells(LRw, ActiveCell.Column)).FillDown
End Sub