Macro

chazzerman01

Board Regular
Joined
Nov 18, 2019
Messages
65
is it possible for a macro to run if the active cell value is different to the value above it
 

Excel Facts

Which came first: VisiCalc or Lotus 1-2-3?
Dan Bricklin and Bob Frankston debuted VisiCalc in 1979 as a Visible Calculator. Lotus 1-2-3 debuted in the early 1980's, from Mitch Kapor.
is it possible for a macro to run if the active cell value is different to the value above it
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
 
Upvote 0
1578479233618.png
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
 
Upvote 0
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?
You said:
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.
 
Upvote 0
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
Sub InsertMultipleRows()
Dim i As Integer
Dim j As Integer
activecell.EntireRow.Select
On Error GoTo Last
i = InputBox("Enter number of columns to insert", "Insert Columns")
For j = 1 To i
Selection.Insert Shift:=xlToDown
CopyOrigin = xlFormatFromRightorAbove
Next j
Last: Exit Sub
End Sub
 
Upvote 0
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:
VBA Code:
Sub Resize_Me()
'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)
tbl.Resize rng
Range("Table1[#All]").Select
End Sub
 
Upvote 0
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
 
Upvote 0

Forum statistics

Threads
1,214,944
Messages
6,122,387
Members
449,080
Latest member
Armadillos

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