VBA - Use variable from InputBox in formula?
Hi!
I've a macro where I need to search for a string, given by InputBox and split the result in to two columns.
How may I use the string from the InputBox, in the forumula?
If I use the following, the code will not search for anything. If I replace the sReturn-variable in the forumla with a fixed string (eq. ""apple"") it will act as intended
Code:
sReturn = InputBox("What to search for?")
'Insert two new columns with format "General" to the right of the selected cell/column
ActiveCell.EntireColumn.Offset(0, 1).Insert
ActiveCell.EntireColumn.Offset(0, 1).Select
ActiveCell.Offset(0, 0).FormulaR1C1 = "Part 1"
ActiveCell.EntireColumn.Offset(0, 1).NumberFormat = "General"
'
ActiveCell.EntireColumn.Offset(0, 1).Insert
ActiveCell.EntireColumn.Offset(0, 1).Select
ActiveCell.Offset(0, 0).FormulaR1C1 = "Part 2"
ActiveCell.EntireColumn.Offset(0, 1).NumberFormat = "General"
'
Dim i, LastRow
LastRow = Range("A" & Rows.Count).End(xlUp).Row
For i = 1 To LastRow - 1
ActiveCell(i + 1, 0).FormulaR1C1 = _
"=IF(ISNUMBER(FIND(sReturn,RC[-1])),LEFT(RC[-1],FIND(sReturn,RC[-1])-1),"""")"
ActiveCell(i + 1, 1).FormulaR1C1 = _
"=IF(ISNUMBER(FIND(sReturn,RC[-2])),SUBSTITUTE(RC[-2],RC[-1]&sReturn,""""),"""")"