Run VBA when any cell within range <>=""

p4nny

Board Regular
Joined
Jan 13, 2015
Messages
246
Hi

Basically, I'm trying to run code when a value is entered in range("A:A"). The code will repopulate specific cells with formulae if the user inserts a new row and enters a value into Range("A:A")

I've searched for an event for INSERT ROW but this has been unsuccessful

Much appreciated
 

Excel Facts

Best way to learn Power Query?
Read M is for (Data) Monkey book by Ken Puls and Miguel Escobar. It is the complete guide to Power Query.
If you determine the amount of rows when opening the WB with
Code:
k=sh.Range("A1048576").end(xlUp).row
You can add another piece of code to a Worksheet_Change event
Code:
lrow=sh.Range("A1048576").end(xlUp).row
If lrow <> k Then
'do code
k = lrow 'this resets the number of rows so the code won't run every time something changes unless you insert a new row
End if
 
Upvote 0
Hi

Thanks for the reply

When I enter the first piece of code as 'Workbook Open' event, I get the error message 'Object Required'

Much appreciated

Code:
Private Sub Workbook_Open()


k = Sh.Range("A1048576").End(xlUp).Row


End Sub
 
Upvote 0
thanks for coming back to me. I should have spotted that!

My code is as follows entered in 'ThisWorkbook'
Code:
Private Sub Workbook_Open()


k = Worksheets("Action plan").Range("A1048576").End(xlUp).Row


End Sub

In the specific tab, code is:

Code:
Private Sub Worksheet_Change(ByVal Target As Range) 
lrow = Worksheets("Action plan").Range("A1048576").End(xlUp).Row
If lrow <> k Then
Worksheets("action plan").Range("ba1") = "hello"


k = lrow 'this resets the number of rows so the code won't run every time something changes unless you insert a new row
End If


End Sub

I get the following error message when inserting a row 'Method 'Range' of object _Worksheet failed. I've simply put "Hello" in the code as a test, so in my understanding "Hello" would appear in cell BA1 when a row is inserted

Many thanks
 
Last edited:
Upvote 0
thanks again!!

the same error appears now and highlights:
Code:
lrow = Worksheets("Action plan").Range("A1048576").End(xlUp).Row

Is there anything you can suggest?

many thanks
 
Upvote 0
The code works perfectly fine on my end. My bet is that your reference is wrong. Please check your references and spelling before asking questions. Note that everything between "" is extremely specific
 
Upvote 0
Thanks. I've tried all you've suggested but without success. I'm looking for an alternate solution as maybe i wasn't clear in my original requirement

appreciate the help
 
Upvote 0
Hia
How about
Code:
Private Sub Worksheet_Change(ByVal Target As Range)

    If Not Target.Count <> 1 And Target.Column = 1 Then
        Target.Offset(, 4).FormulaR1C1 = "=rc[-4]+rc[-3]"
    End If
    
End Sub
This will insert a formula into column E when a change is made to column A
 
Upvote 0

Forum statistics

Threads
1,223,957
Messages
6,175,625
Members
452,661
Latest member
Nonhle

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