Change Event insert formula

ANE0709

Board Regular
Joined
Feb 2, 2022
Messages
65
Office Version
  1. 365
Platform
  1. Windows
i have the following change event that i have modified to insert row count. Unfortunately im still learning change events procedures and need a little help putting in the formula syntax. how do i correct this?

if Column C <> blank then insert formula =Row()-3 in target.row column A. Headers are in row 3. data starts on row 4.

If Target.Column = 3 And Target.Row > 3 And Target.Value <> "" Then
Application.EnableEvents = False
Target.Offset(0, -2) = Formula = "=ROW()-3" <<<<<<this just returns "FALSE" in column A. it should be row count.
Application.EnableEvents = True
 

Excel Facts

What did Pito Salas invent?
Pito Salas, working for Lotus, popularized what would become to be pivot tables. It was released as Lotus Improv in 1989.
What is the objective here?
Do not understand all this: Target.Offset(0, -2) = Formula = "=ROW()-3"
 
Upvote 0
You have one too many = signs, try
VBA Code:
Target.Offset(0, -2).Formula = "=ROW()-3"
 
Upvote 0
Solution
I would not use a formula and do it this way:
VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)
'Modified  5/13/2022  3:02:28 PM  EDT
If Target.Column = 3 And Target.Row > 3 And Target.Value <> "" Then
Application.EnableEvents = False
Target.Offset(0, -2).Value = Target.Row - 3
Application.EnableEvents = True
End If
End Sub
 
Upvote 0
the end goal was to count the rows being used. formula is the only was i currently know which is why i was going that direction. Both suggestions mentioned work out great and have the same end purpose. thank you both!
 
Upvote 0
the end goal was to count the rows being used. formula is the only was i currently know which is why i was going that direction. Both suggestions mentioned work out great and have the same end purpose. thank you both!
I thought as much.
Glad I was able to help you.
Come back here to Mr. Excel next time you need additional assistance.
 
Upvote 0

Forum statistics

Threads
1,213,482
Messages
6,113,916
Members
448,533
Latest member
thietbibeboiwasaco

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