vba Formula Problem

Lochnagar

New Member
Joined
Jan 28, 2008
Messages
43
Hi,

I'm wanting to input a formula (and not a value) into the activecell, which adds the first cell to the left and right of the activecell e.g. if my activecell was B1 the formula would be "=A1+C1"

What I'm wondering is, is it possible to generalise the above, that is, if my activecell was E1 the formula that vba would insert would be "=D1+F1" or if it G1 the formula inputed would be "=F1+H1" and so on... ?

...something kinda along these lines

activecell = "=[cell, left of activecell] + [cell, right of activecell]"

Any help or suggestions would be greatly appreciated.

Thanks,
Lochnagar
 

Excel Facts

Last used cell?
Press Ctrl+End to move to what Excel thinks is the last used cell.
"=" & ActiveCell.Offset(0, -1).Address(False, False) & " + " & ActiveCell.Offset(0, 1).Address(False, False)
 
Upvote 0
Hi,

I'm wanting to input a formula (and not a value) into the activecell, which adds the first cell to the left and right of the activecell e.g. if my activecell was B1 the formula would be "=A1+C1"

What I'm wondering is, is it possible to generalise the above, that is, if my activecell was E1 the formula that vba would insert would be "=D1+F1" or if it G1 the formula inputed would be "=F1+H1" and so on... ?

...something kinda along these lines

activecell = "=[cell, left of activecell] + [cell, right of activecell]"

Any help or suggestions would be greatly appreciated.

Thanks,
Lochnagar

Something like this, perhaps:
Code:
    With ActiveCell
        .Formula = "=" & .Offset(0, -1).Address(0, 0) & _
            "+" & .Offset(0, 1).Address(0, 0)
    End With

Bear in mind the implications if the activecell is in the first or last column of the worksheet....
 
Upvote 0

Forum statistics

Threads
1,223,243
Messages
6,170,971
Members
452,371
Latest member
Frana

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