Insert Formula to cell next to active cell

Truiz

Active Member
Joined
Jul 14, 2014
Messages
339
Good Morning,

I'm trying to come up with a code to insert a formula in the column next to the active cell

for example if active cell is A2 i want to insert the formula in B2 and then another one to cell C2

The formulas themselves have references to the active cell such as LEFT(A2,FIND(" ",A2)-1) since not all the time the active cell is going to be A2 how could I accomplish this?

does ActiveCell.Offset(RowOffset:=0, ColumnOffset:=+1).InsertFormula = LEFT(ActiveCell,FIND(" ",ActiveCell)-1) sound like a possible thing?

Regards,
 

Excel Facts

Formula for Yesterday
Name Manager, New Name. Yesterday =TODAY()-1. OK. Then, use =YESTERDAY in any cell. Tomorrow could be =TODAY()+1.
I'd be inclined to use R1C1 format in this case:

Code:
ActiveCell.Offset(0,1).FormulaR1C1 = "=LEFT(RC[-1],FIND("" "",RC[-1])-1)"

WBD
 
Upvote 0
Obviously, you will get errors if the formula does not handle them.
Code:
Sub F2R()
  Dim s As String
  With ActiveCell
    If .Column + 3 > Columns.Count Then Exit Sub
    'LEFT(A2,FIND(" ",A2)-1)
    s = "=LEFT(" & .Address(False, False) & ",FIND(" & _
      """ ""," & .Address(False, False) & ")-1)"
    .Offset(, 1).Formula = s
    .Offset(, 2).Formula = s
  End With
End Sub
 
Upvote 0

Forum statistics

Threads
1,214,904
Messages
6,122,169
Members
449,070
Latest member
webster33

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