macro messing up table

daveyc18

Well-known Member
Joined
Feb 11, 2013
Messages
755
Office Version
  1. 365
  2. 2010
i have a table with three columns...whenever i use the macro to enter new data in the table, it messes it up and it's no longer dynamic. after the macro, if i manually enter data again, the table does not expand.

Code:
'put time stamp
Sheets("Time Stamp").Select


finalrow = Cells(Rows.Count, "A").End(xlUp).Row


'time
Range("c" & finalrow + 1).Select
ActiveCell.FormulaR1C1 = "=now()"
ActiveCell.Copy
ActiveCell.PasteSpecial xlValues


'date
ActiveCell.Offset(, -1).Select
ActiveCell.FormulaR1C1 = "=TODAY()"
ActiveCell.Copy
ActiveCell.PasteSpecial xlValues




Application.CutCopyMode = False
 

Excel Facts

Highlight Duplicates
Home, Conditional Formatting, Highlight Cells, Duplicate records, OK to add pink formatting to any duplicates in selected range.
Nothing in that code indicates you are working with a true Excel table,
but if you are, try this
Code:
Dim oLo As ListObject
Dim oNewrow As ListRow

Set oLo = Sheets("Time Stamp").ListObjects(1)
Set oNewrow = oLo.ListRows.Add
With oNewrow.Range
    'date
    .Cells(1, 2).Value = Date
    'time
    .Cells(1, 3).Value = Time
End With
a couple of links for more insight on tables
https://www.jkp-ads.com/Articles/Excel2007TablesVBA.asp?AllComments=True
https://www.thespreadsheetguru.com/blog/2014/6/20/the-vba-guide-to-listobject-excel-tables
 
Upvote 0
Nothing in that code indicates you are working with a true Excel table,
but if you are, try this
Code:
Dim oLo As ListObject
Dim oNewrow As ListRow

Set oLo = Sheets("Time Stamp").ListObjects(1)
Set oNewrow = oLo.ListRows.Add
With oNewrow.Range
    'date
    .Cells(1, 2).Value = Date
    'time
    .Cells(1, 3).Value = Time
End With
a couple of links for more insight on tables
https://www.jkp-ads.com/Articles/Excel2007TablesVBA.asp?AllComments=True
https://www.thespreadsheetguru.com/blog/2014/6/20/the-vba-guide-to-listobject-excel-tables


it's definuitely a table...i see when i check the name manager and when I manually type in something, a new row is autoamtically added.

to expand on what i said originally, when i run my ORIGINAL macro code, it looks like the new row is a new table (the filters show up in the new row and the filters still exist in the headers of the original table). when I run the code again, the table is not expanded.
 
Upvote 0
it's definuitely a table...i see when i check the name manager and when I manually type in something, a new row is autoamtically added.

to expand on what i said originally, when i run my ORIGINAL macro code, it looks like the new row is a new table (the filters show up in the new row and the filters still exist in the headers of the original table). when I run the code again, the table is not expanded.

but your code worked!! thanks!

googled listobjects ...good to know!

now i know why when I was trying to reference a table for advance filtering purposes it wasnt working
 
Last edited:
Upvote 0

Forum statistics

Threads
1,223,889
Messages
6,175,224
Members
452,620
Latest member
dsubash

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