Formatting a range of data as a Table

bosko2

New Member
Joined
Nov 3, 2020
Messages
22
Office Version
  1. 365
Platform
  1. Windows
Hi All,

Just a quick one, I have the below VBA Code where a user selects their data using drop downs on an opening sheet titled 'Report Builder'. The code takes the filtered data from a Master table titled 'Actions' (this master table is hidden and protected), and performs a 'Paste Special' onto a blank worksheet titled 'My team's actions'. I have attempted to perform some minor formatting on the new sheet, without much luck.

Specifically, can the new range of data on the 'My team's actions' be formatted as a table once the paste special has ceased?


VBA Code:
Set DbExtract = ThisWorkbook.Sheets("Actions")
    Set DuplicateRecords = ThisWorkbook.Sheets("My team's Actions")
   
    With Sheets("Report Creator")
   If .Cells(2, 1) <> "" Then
      Sheets("Actions").Range("A1").AutoFilter 11, .Cells(2, 1).Value
   End If
   If .Cells(2, 2) <> "" Then
      Sheets("Actions").Range("A1").AutoFilter 12, .Cells(2, 2).Value
   End If
   If .Cells(2, 3) <> "" Then
      Sheets("Actions").Range("A1").AutoFilter 13, .Cells(2, 3).Value
   End If
   .Select
End With

    Sheets("Safety Accountability Dashboard").Select
    Sheets("Actions").Visible = True
    Sheets("Actions").Select
    Sheets("My team's actions").Visible = True

    DbExtract.Range("A1:BF9999").SpecialCells(xlCellTypeVisible).Copy
    DuplicateRecords.Cells(1, 1).PasteSpecial
   
    Sheets("Actions").Select
    ActiveWindow.SelectedSheets.Visible = False
    Sheets("My team's actions").UsedRange.AutoFilter
    Selection.WrapText = True
    Sheets("My t[COLOR=rgb(0, 0, 0)]eam's actions").Select
    ActiveSheet.Rows("1:1").Select
    Selection.Font.Bold = True[/COLOR]
    Selection.HorizontalAlignment = xlLeft
   
    Sheets("Report Creator").Select
    ActiveWindow.SelectedSheets.Visible = False
    Sheets("Safety Accountability Dashboard").Select


End Sub


Any assistance would be greatly appreciated,
bosko2
 

Excel Facts

How can you automate Excel?
Press Alt+F11 from Windows Excel to open the Visual Basic for Applications (VBA) editor.
You can easily convert a range to a table like this.
VBA Code:
    With DuplicateRecords
        .ListObjects.Add xlSrcRange, .Range("A1").CurrentRegion
    End With
 
Upvote 0
Right after you've pasted the data into 'My team's actions'.
VBA Code:
DuplicateRecords.Cells(1, 1).PasteSpecial

With DuplicateRecords
    .ListObjects.Add xlSrcRange, .Range("A1").CurrentRegion
End With
 
Upvote 0
Right after you've pasted the data into 'My team's actions'.
VBA Code:
DuplicateRecords.Cells(1, 1).PasteSpecial

With DuplicateRecords
    .ListObjects.Add xlSrcRange, .Range("A1").CurrentRegion
End With
So sorry dude, I'm having trouble with integrating it into my VBA; so I thought that I will post the entire VBA to give you more context:

VBA Code:
Sub Report_Builder()


Sheets("My team's investigations").Range("A1:BF9999").ClearContents
Sheets("My team's actions").Range("A1:BF9999").ClearContents

With Sheets("Report Creator")
   If .Cells(2, 1) <> "" Then
      Sheets("Investigations").Range("A1").AutoFilter 14, .Cells(2, 1).Value
   End If
   If .Cells(2, 2) <> "" Then
      Sheets("Investigations").Range("A1").AutoFilter 15, .Cells(2, 2).Value
   End If
   If .Cells(2, 3) <> "" Then
      Sheets("Investigations").Range("A1").AutoFilter 16, .Cells(2, 3).Value
   End If
   .Select
End With


Sheets("Report Creator").Select

Sheets("Safety Accountability Dashboard").Visible = True

Sheets("Safety Accountability Dashboard").Select



    Dim DbExtract, DuplicateRecords As Worksheet
    Set DbExtract = ThisWorkbook.Sheets("Investigations")
    Set DuplicateRecords = ThisWorkbook.Sheets("My team's investigations")

    Sheets("Safety Accountability Dashboard").Select
    Sheets("Investigations").Visible = True
    Sheets("Investigations").Select
    Sheets("My team's investigations").Visible = True

    DbExtract.Range("A1:BF9999").SpecialCells(xlCellTypeVisible).Copy
    DuplicateRecords.Cells(1, 1).PasteSpecial
    
    Sheets("Investigations").Select
    ActiveWindow.SelectedSheets.Visible = False
    Sheets("My team's investigations").UsedRange.AutoFilter
    Selection.WrapText = True
    ActiveSheet.Rows("1:1").Select
    Selection.Font.Bold = True
    Selection.HorizontalAlignment = xlLeft

    Set DbExtract = ThisWorkbook.Sheets("Actions")
    Set DuplicateRecords = ThisWorkbook.Sheets("My team's Actions")
    
    With Sheets("Report Creator")
   If .Cells(2, 1) <> "" Then
      Sheets("Actions").Range("A1").AutoFilter 11, .Cells(2, 1).Value
   End If
   If .Cells(2, 2) <> "" Then
      Sheets("Actions").Range("A1").AutoFilter 12, .Cells(2, 2).Value
   End If
   If .Cells(2, 3) <> "" Then
      Sheets("Actions").Range("A1").AutoFilter 13, .Cells(2, 3).Value
   End If
   .Select
End With

    Sheets("Safety Accountability Dashboard").Select
    Sheets("Actions").Visible = True
    Sheets("Actions").Select
    Sheets("My team's actions").Visible = True

    DbExtract.Range("A1:BF9999").SpecialCells(xlCellTypeVisible).Copy
    DuplicateRecords.Cells(1, 1).PasteSpecial
    
    Sheets("Actions").Select
    ActiveWindow.SelectedSheets.Visible = False
    Sheets("My team's actions").UsedRange.AutoFilter
    Selection.WrapText = True
    Sheets("My team's actions").Select
    ActiveSheet.Rows("1:1").Select
    Selection.Font.Bold = True
    Selection.HorizontalAlignment = xlLeft
    
    Sheets("Report Creator").Select
    ActiveWindow.SelectedSheets.Visible = False
    Sheets("Safety Accountability Dashboard").Select


End Sub
 
Upvote 0

Forum statistics

Threads
1,214,608
Messages
6,120,500
Members
448,968
Latest member
screechyboy79

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