View Single Post
 
Old 12-22-2016, 08:33 AM
NoSparks NoSparks is offline Windows 7 64bit Office 2010 64bit
Excel Hobbyist
 
Join Date: Nov 2013
Location: British Columbia, Canada
Posts: 842
NoSparks is a glorious beacon of lightNoSparks is a glorious beacon of lightNoSparks is a glorious beacon of lightNoSparks is a glorious beacon of lightNoSparks is a glorious beacon of light
Default

Did you have a look at my reply to your question here?

You can calculate the last row of the table, the input box is not necessary. It only gives the user a chance to increase the difficulty for you to program against them screwing things up. (Try entering the wrong number, a decimal number or the word "hello")

What is the goal here?

It appears you want the added column and row to appear to be part of the table without being part of the table.

What are you actually trying to do? and why?

If the column you're adding is always immediately right of the table, like the row being immediately below the table, no input boxes are required.
Code:
Sub Add_Row_and_Column()
    Dim oLo As ListObject
    Dim StrtRow As Long, EndRow As Long
    Dim StrtCol As Long, EndCol As Long
    Dim i As Integer

With ThisWorkbook.Sheets("Sheet1")
    Set oLo = .ListObjects(1)    '<~~ first table on sheet
    'establish table location
    With oLo
        StrtRow = .ListRows(1).Range.Row
        EndRow = .ListRows.Count + StrtRow - 1
        StrtCol = .ListColumns(1).Range.Row
        EndCol = .ListColumns.Count + StrtCol - 1
    End With
    'add column on right of table
    .Columns(EndCol + 1).Insert
    For i = StrtRow To EndRow
        .Cells(i, EndCol + 1).Interior.Color = .Cells(i, StrtCol).DisplayFormat.Interior.Color
    Next i
    'add row below table
    .Rows(EndRow + 1).Insert
    .Range(Cells(EndRow + 1, StrtCol), Cells(EndRow + 1, EndCol + 1)).Interior.Color = _
                            .Cells(EndRow - 1, StrtCol).DisplayFormat.Interior.Color
End With
End Sub

Last edited by NoSparks; 12-22-2016 at 11:04 AM. Reason: added code
Reply With Quote