In a macro, I am trying to enter a formula into a cell and this is the code I am using:
Cells(11, 10).Formula = "=LEFT(I11,(FIND(" ",I11,1)-1))"
The problem is, excel is trying to enter "=LEFT(I11,(FIND(" as the formula's text instead of the entire formula of =LEFT(I11,(FIND(" ",I11,1)-1)). The " " in the formula is the problem, but I don't know how to work around it.
The purpose of the macro is to split the text in I11 into three columns. Here is sample:
07436-72202 AGP STEERING PUMP
to 3 columns of
07436-72202
AGP
STEERING PUMP
Here is the complete macro:
Sub Format()
'Delete Section
Range("B10:H10").Select
Selection.Delete Shift:=xlUp
Range("B10").Select
'Insert Formulas
Cells(11, 9).Formula = "=TRIM(A11)"
Cells(11, 10).Formula = "=LEFT(I11,(FIND(" ",I11,1)-1))"
Cells(11, 11).Formula = "=TRIM(MID(SUBSTITUTE(I11," ",REPT(" ", 100)),100,100))"
Cells(11, 12).Formula = "=RIGHT(I11,LEN(I11)-SEARCH(" ",I11,SEARCH(" ",I11))-4)"
Range("I11:L4000").FillDown
End Sub
Any help is appreciated!
Cells(11, 10).Formula = "=LEFT(I11,(FIND(" ",I11,1)-1))"
The problem is, excel is trying to enter "=LEFT(I11,(FIND(" as the formula's text instead of the entire formula of =LEFT(I11,(FIND(" ",I11,1)-1)). The " " in the formula is the problem, but I don't know how to work around it.
The purpose of the macro is to split the text in I11 into three columns. Here is sample:
07436-72202 AGP STEERING PUMP
to 3 columns of
07436-72202
AGP
STEERING PUMP
Here is the complete macro:
Sub Format()
'Delete Section
Range("B10:H10").Select
Selection.Delete Shift:=xlUp
Range("B10").Select
'Insert Formulas
Cells(11, 9).Formula = "=TRIM(A11)"
Cells(11, 10).Formula = "=LEFT(I11,(FIND(" ",I11,1)-1))"
Cells(11, 11).Formula = "=TRIM(MID(SUBSTITUTE(I11," ",REPT(" ", 100)),100,100))"
Cells(11, 12).Formula = "=RIGHT(I11,LEN(I11)-SEARCH(" ",I11,SEARCH(" ",I11))-4)"
Range("I11:L4000").FillDown
End Sub
Any help is appreciated!
Last edited: