• Skip to main content
  • Skip to header right navigation
  • Skip to site footer

My Online Training Hub

Learn Dashboards, Excel, Power BI, Power Query, Power Pivot

  • Courses
  • Pricing
    • Free Courses
    • Power BI Course
    • Excel Power Query Course
    • Power Pivot and DAX Course
    • Excel Dashboard Course
    • Excel PivotTable Course – Quick Start
    • Advanced Excel Formulas Course
    • Excel Expert Advanced Excel Training
    • Excel Tables Course
    • Excel, Word, Outlook
    • Financial Modelling Course
    • Excel PivotTable Course
    • Excel for Customer Service Professionals
    • Excel for Operations Management Course
    • Excel for Decision Making Under Uncertainty Course
    • Excel for Finance Course
    • Excel Analysis ToolPak Course
    • Multi-User Pricing
  • Resources
    • Free Downloads
    • Excel Functions Explained
    • Excel Formulas
    • Excel Add-ins
    • IF Function
      • Excel IF Statement Explained
      • Excel IF AND OR Functions
      • IF Formula Builder
    • Time & Dates in Excel
      • Excel Date & Time
      • Calculating Time in Excel
      • Excel Time Calculation Tricks
      • Excel Date and Time Formatting
    • Excel Keyboard Shortcuts
    • Excel Custom Number Format Guide
    • Pivot Tables Guide
    • VLOOKUP Guide
    • ALT Codes
    • Excel VBA & Macros
    • Excel User Forms
    • VBA String Functions
  • Members
    • Login
    • Password Reset
  • Blog
  • Excel Webinars
  • Excel Forum
    • Register as Forum Member

Copying tables|VBA & Macros|Excel Forum|My Online Training Hub

You are here: Home / Copying tables|VBA & Macros|Excel Forum|My Online Training Hub
Avatar
sp_LogInOut Log In sp_Registration Register
sp_Search Search
Advanced Search|Last Search Results
Search
Forum Scope




Match



Forum Options



Minimum search word length is 3 characters - maximum search word length is 84 characters
sp_Search Search
sp_RankInfo
Lost password?
sp_CrumbsHome HomeExcel ForumVBA & MacrosCopying tables
sp_PrintTopic sp_TopicIcon
Copying tables
Avatar
Sal Veltri
California
Member
Members

Excel Tables
Level 0
Forum Posts: 28
Member Since:
May 27, 2019
sp_UserOfflineSmall Offline
1
September 25, 2019 - 12:57 pm
sp_Permalink sp_Print

i have 12 tables on one sheet, each table is a header, first row with formulas only, no data. Each one of these are needed on another sheet. Using the following code:

With shtPlaces
' .Visible = xlSheetVisible
.ListObjects("tblSampleDay1F1").Range.Copy Destination:= _
Range("C33")
shtBDP.ListObjects(1).Name = "tblDay1Front1"
.ListObjects("tblSampleDay1F2").Range.Copy Destination:= _
Range("C46")
shtBDP.ListObjects(2).Name = "tblDay1Front2"
.ListObjects("tblSampleDay1B1").Range.Copy Destination:= _
Range("G33")
shtBDP.ListObjects(3).Name = "tblDay1Back1"
.ListObjects("tblSampleDay1F1").Range.Copy Destination:= _
Range("G46")
shtBDP.ListObjects(4).Name = "tblDay1Back2"
.ListObjects("tblSampleDay1F1").Range.Copy Destination:= _
Range("K33")
shtBDP.ListObjects(5).Name = "tblDay1Totat1"
.ListObjects("tblSampleDay1F1").Range.Copy Destination:= _
Range("K46")
shtBDP.ListObjects(6).Name = "tblDay1Totat2"
.ListObjects("tblSampleDay2F1").Range.Copy Destination:= _
Range("C33")
shtBDP.ListObjects(7).Name = "tblDay2Front1"
.ListObjects("tblSampleDay2F2").Range.Copy Destination:= _
Range("C93")
shtBDP.ListObjects(8).Name = "tblDay2Front2"
.ListObjects("tblSampleDay2B1").Range.Copy Destination:= _
Range("C106")
shtBDP.ListObjects(9).Name = "tblDay2Back1"
.ListObjects("tblSampleDay2F1").Range.Copy Destination:= _
Range("G93")
shtBDP.ListObjects(10).Name = "tblDay2Back2"
.ListObjects("tblSampleDay2F1").Range.Copy Destination:= _
Range("G106")
shtBDP.ListObjects(11).Name = "tblDay2Totat1"
.ListObjects("tblSampleDay2F1").Range.Copy Destination:= _
Range("K93")
shtBDP.ListObjects(12).Name = "tblDay2Totat2"
.ListObjects("tblSampleDay2F1").Range.Copy Destination:= _
Range("K106")
End With

The works fine until line shtBDP.ListObjects(7).Name = "tblDay2Front1". Here it seems to change the first table named "tblDay1Front1" to "tblDay2Front1" instead of renaming the table just pasted.

heres a link to the file: https://www.dropbox.com/sh/x9n.....Y-Rqa?dl=0

Any help would be appreciated.

sp_AnswersTopicSeeAnswer See Answer
Avatar
Catalin Bombea
Iasi, Romania
Admin
Level 10
Forum Posts: 1807
Member Since:
November 8, 2013
sp_UserOfflineSmall Offline
2
September 26, 2019 - 1:38 pm
sp_Permalink sp_Print sp_EditHistory

Hi Sal,

The file from the link provided does not contain the code you described.

Use shtBDP.ListObjects("tblSampleDay1F1") reference to make sure you are referring to the correct table.

I see you are trying to paste a table from a sheet to another, then you "assume" that the newly added table has the index 12:

.ListObjects("tblSampleDay2F1").Range.Copy Destination:= _
Range("K93")
shtBDP.ListObjects(12).Name = "tblDay2Totat2"

Using shtBDP.ListObjects(12) is not precise, you cannot know for sure that shtBDP.ListObjects(12) is the table named "tblSampleDay1F1" or it's the table "tblSampleDay2F1"

To see the index number associated to each table, use:

For i=1 to 12

debug.print "Table no. " & i & "starts in cell " & shtBDP.ListObjects(i).Range.Cells(1).Address

Next i

You can rename the table, if you're sure it's in the correct location:

If shtBDP.ListObjects(i).Range.Cells(1).Address="$K$93" Then shtBDP.ListObjects(i).Name = "tblDay2Totat2"

sp_AnswersTopicAnswer
Answers Post
Avatar
Sal Veltri
California
Member
Members

Excel Tables
Level 0
Forum Posts: 28
Member Since:
May 27, 2019
sp_UserOfflineSmall Offline
3
September 27, 2019 - 6:29 am
sp_Permalink sp_Print

Thank you for the assistance - Sal

sp_Feed
Go to top
Forum Timezone: Australia/Brisbane
Most Users Ever Online: 245
Currently Online: Ngoc Tinh
Guest(s) 11
Currently Browsing this Page:
1 Guest(s)
Top Posters:
SunnyKow: 1432
Anders Sehlstedt: 870
Purfleet: 412
Frans Visser: 346
David_Ng: 306
lea cohen: 219
A.Maurizio: 202
Jessica Stewart: 202
Aye Mu: 201
jaryszek: 183
Newest Members:
michael serna
mashal sana
Tiffany Kang
Leah Gillmore
Sopi Yuniarti
LAFONSO HERNANDEZ
Hayden Hao
Angela chen
Sean Moore
John Chisholm
Forum Stats:
Groups: 3
Forums: 24
Topics: 6215
Posts: 27248

 

Member Stats:
Guest Posters: 49
Members: 31897
Moderators: 3
Admins: 4
Administrators: Mynda Treacy, Philip Treacy, Catalin Bombea, FT
Moderators: MOTH Support, Velouria, Riny van Eekelen
© Simple:Press —sp_Information

Sidebar

Blog Categories

  • Excel
  • Excel Charts
  • Excel Dashboard
  • Excel Formulas
  • Excel PivotTables
  • Excel Shortcuts
  • Excel VBA
  • General Tips
  • Online Training
  • Outlook
  • Power Apps
  • Power Automate
  • Power BI
  • Power Pivot
  • Power Query
microsoft mvp logo
trustpilot excellent rating
Secured by Sucuri Badge
MyOnlineTrainingHub on YouTube Mynda Treacy on Linked In Mynda Treacy on Instagram Mynda Treacy on Twitter Mynda Treacy on Pinterest MyOnlineTrainingHub on Facebook
 

Company

  • About My Online Training Hub
  • Disclosure Statement
  • Frequently Asked Questions
  • Guarantee
  • Privacy Policy
  • Terms & Conditions
  • Testimonials
  • Become an Affiliate

Support

  • Contact
  • Forum
  • Helpdesk - For Technical Issues

Copyright © 2023 · My Online Training Hub · All Rights Reserved. Microsoft and the Microsoft Office logo are trademarks or registered trademarks of Microsoft Corporation in the United States and/or other countries. Product names, logos, brands, and other trademarks featured or referred to within this website are the property of their respective trademark holders.