PDA

View Full Version : make a table bigger at the touch of a button



RuneDefour
04-05-2023, 07:25 AM
when I press button 2, a row should be added at the bottom of the table. but it doesn't work i keep getting an error message. how else should I do it?


Private Sub CommandButton2_Click()
Dim stockTable As ListObject
Set stockTable = ActiveSheet.ListObjects("stock2")
stockTable.ListRows.Add
With stockTable.ListRows(stockTable.ListRows.Count).Range
.Borders(xlEdgeTop).LineStyle = xlContinuous
.Borders(xlEdgeTop).Weight = xlThin
.Borders(xlEdgeBottom).LineStyle = xlContinuous
.Borders(xlEdgeBottom).Weight = xlThin
.Borders(xlEdgeLeft).LineStyle = xlContinuous
.Borders(xlEdgeLeft).Weight = xlThin
.Borders(xlEdgeRight).LineStyle = xlContinuous
.Borders(xlEdgeRight).Weight = xlThin
End With
End Sub

Bob Phillips
04-05-2023, 10:01 AM
Works fine for me. Two questions
- what error do you get?
- why are you creating borders on the table, doesn't the table style set all of that up for you?

Aussiebear
04-05-2023, 11:18 AM
RuneDefour, please add the code tags to your code in future. You have been asked to do so prior to this, but still you fail to do so.