Macro

chazzerman01

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

My Aswer Is This

Well-known Member
Joined
Jul 5, 2014
Messages
16,274
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
 

chazzerman01

Board Regular
Joined
Nov 18, 2019
Messages
51
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
 

My Aswer Is This

Well-known Member
Joined
Jul 5, 2014
Messages
16,274
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.
 

chazzerman01

Board Regular
Joined
Nov 18, 2019
Messages
51
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
 

My Aswer Is This

Well-known Member
Joined
Jul 5, 2014
Messages
16,274
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
 

chazzerman01

Board Regular
Joined
Nov 18, 2019
Messages
51
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
 

Forum statistics

Threads
1,081,956
Messages
5,362,383
Members
400,673
Latest member
RobBro1987

Some videos you may like

This Week's Hot Topics

  • populate from drop list with multiple tables
    Hi All, i have a drop list that displays data, what i want is when i select one of those from the list to populate text from different tables on...
  • Find list of words from sheet2 in sheet1 before a comma and extract text vba
    Hi Friends, Trying to find the solution on my task. But did not find suitable one to the need. Here is my query and sample file with details...
  • Dynamic Formula entry - VBA code sought
    Hello, really hope one of you experts can help with this - i've spent hours on this and getting no-where. .I have a set of data (more rows than...
  • Listbox Header
    Have a named range called "AccidentsHeader" Within my code I have: [CODE]Private Sub CommandButton1_Click() ListBox1.RowSource =...
  • Complex Heat Map using conditional formatting
    Good day excel world. I have a concern. Below link have a list of countries that carries each country unique data. [URL...
  • Conditional formatting
    Hi good morning, hope you can help me please, I have cells P4:P54 and if this cell is equal to 1 then i want row O to say "Fully Utilised" and to...
Top