enter formula using activecell and offset

JohnZ1156

Board Regular
Joined
Apr 10, 2021
Messages
180
Office Version
  1. 2021
Platform
  1. Windows
I have a table where I'd like the macro to enter a formula BEFORE I enter the actual value.

I would like it to enter a formula that says, in the activecell, put the formula (offset(0,-1) minus (offset(-1, -1)
Then I would like it to show me that amount.
But then, I have an input box and I'd like whatever I enter into the input box to REPLACE the formula in the activecell.

VBA Code:
    With ActiveCell
        .Offset(0, 0).Value = .Offset(0, -1).Value - .Offset(-1, -1).Value
    End With
    
    Trip = InputBox("Please enter the Trip Distance.", "Trip Distance", Default, XPos:=2880, YPos:=5760)
    ActiveCell.Value = ActiveCell.Value & Trip
    ActiveCell.Offset(0, 1).Select
 

Excel Facts

Easy bullets in Excel
If you have a numeric keypad, press Alt+7 on numeric keypad to type a bullet in Excel.
something like this:
VBA Code:
    With ActiveCell
        .Formula = "=" & .Offset(0, -1).Address & "-" & .Offset(-1, -1).Address
        
        Trip = InputBox("Please enter the Trip Distance.", "Trip Distance", .Value, XPos:=2880, YPos:=5760)
        If IsNumeric(Trip) Then .Value = Trip
        .Offset(0, 1).Select
    End With
 
Upvote 0
Solution
something like this:
VBA Code:
    With ActiveCell
        .Formula = "=" & .Offset(0, -1).Address & "-" & .Offset(-1, -1).Address
       
        Trip = InputBox("Please enter the Trip Distance.", "Trip Distance", .Value, XPos:=2880, YPos:=5760)
        If IsNumeric(Trip) Then .Value = Trip
        .Offset(0, 1).Select
    End With
Works exactly as I wanted.
Thank you !!!
 
Upvote 0

Forum statistics

Threads
1,223,889
Messages
6,175,226
Members
452,620
Latest member
dsubash

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