How do I create a table from selected columns in a dynamic range

davidmyers

Board Regular
Joined
Jan 29, 2017
Messages
88
Office Version
  1. 2016
Platform
  1. Windows
Hi, how do I display selected columns from a dynamic range in a table, make changes in the table and insert the changes back into the worksheet?


Thanks for any help
David
 

Excel Facts

Fastest way to copy a worksheet?
Hold down the Ctrl key while dragging tab for Sheet1 to the right. Excel will make a copy of the worksheet.
This is the code I came up with
Code:
Private Sub CreateTable()
Dim frstRow As Long, lstRow As Long, cnt As Long, i As Long, j As Long
Dim rng As Range
Dim TableName As String
   cnt = 0
    Do While (ActiveCell.Offset(cnt, 0).Value = ActiveCell.Offset(cnt - 1, 0).Value)
       cnt = cnt - 1
    Loop
    frstRow = ActiveCell.Row + cnt
    cnt = 0
    Do While (ActiveCell.Offset(cnt, 0).Value = ActiveCell.Offset(cnt + 1, 0).Value)
       cnt = cnt + 1
    Loop
    lstRow = ActiveCell.Row + cnt
    Set rng = Application.Range("Complaints!A" & frstRow & ":K" & lstRow)
    With rng
        .Sort Key1:=.Range("Complaints!D" & frstRow & ":D" & lstRow), Order1:=xlAscending _
             , Key2:=.Range("Complaints!E" & frstRow & ":E" & lstRow), Order1:=xlAscending _
             , Key3:=.Range("Complaints!F" & frstRow & ":F" & lstRow), Order1:=xlAscending, Header:=xlGuess
    End With
    Set rng = Application.Range("Complaints!A" & frstRow & ":K" & lstRow)
    TableName = "SpeciesTbl"
    ActiveSheet.ListObjects.Add(xlSrcRange, rng, , xlYes).Name = TableName
End Sub

I'm getting an error 1004 "a table can't overlap another table"

This is my 1st attempt at tables - was expecting to see a table that I could work on open on top of the ActiveSheet is that correct?

Please could you point me in the direction to do something like this

Thanks
David
 
Upvote 0

Forum statistics

Threads
1,224,812
Messages
6,181,088
Members
453,021
Latest member
Justyna P

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