Sure. A script can run when ever you activate it.
Now you could write a script to tell the script to not run if certain conditions exist.
Are you saying you do not want the script to run if.
The script would run and immediately stop
on my sheet, as you can see on the far left column the names are judy 2 then it goes Charlie. im trying to get it so that if I add a row in the bottom of the table and then wrote bob for example in the same column which it says Charlie, then it runs a macro
Well I would need more information
So we are dealing with a Excel Table Named what. All Tables have a name.
And we are dealing with a Excel Table here not just a Excel Sheet
A Table is a range on a sheet
Lots of people when they say Table they mean sheet
So how do you plan to add this new row?
so that if I add a row in the bottom of the table
And what does Bob has to do with this?
Will it always be Bob
And tell me what will your script do that you plan to run?
Maybe explain in more detail what your ultimate Goal here is.
I haven't named the table, the sheets called work schedule but the actual table don't have a name just headers. basically the names on the left are the names for different jobs that's why theres a block of "judy 2" and Charlie, my complete aim with this macro is so that when I add another row into the table if I enter a new name/ value in the same column as where it says Charlie and judy, it then automatically runs this macro
Dim i As Integer
Dim j As Integer
On Error GoTo Last
i = InputBox("Enter number of columns to insert", "Insert Columns")
For j = 1 To i
CopyOrigin = xlFormatFromRightorAbove
Last: Exit Sub
Well if it's a true Excel Table it has a name. Even thou you say it has no name.
And to insert rows in a Table you do not do it the way your script works.
Try this script it assumes you only have one Table on your sheet.
To see a Table name do this:
1.Click someplace on the Table
2. On The Ribbon click on design
3. Look to the far left on the ribbon and you will see the Table name
Now I have no way of telling the script to add more rows when you enter some data on the last row of the table.
See that would be called a auto sheet event script and I do those but do not have a solution that will add new rows just because enter data into the last row.
Does this have anything to do with wanting to always move the Totals Row down?
If so I have a solution where the Totals row can be anywhere on the sheet
Try this script:
'Modified 1/8/2020 8:49:39 AM EST
Dim rng As Range
Dim ans As Long
ans = InputBox("How Many Rows")
Dim tbl As ListObject
Set tbl = ActiveSheet.ListObjects("Table1")
Set rng = Range("Table1[#All]").Resize(tbl.Range.Rows.Count + ans, tbl.Range.Columns.Count)
also ive tried your code and it doesn't quite work, it allows me to add in new rows but it doesn't automatically work, I think ive just explained it like a spanner.
basically, in column A in the photo, the values in the cells are judy 2 and Charlie, and I wanted it so that if I made another row in the table, and wrote in column A (under the cells that say Charlie) a different value as an example im going to use bob, then the macro would realise that there's a different value and then would display the message to add in rows. I hope this helps explain a little bit more