Solved

Cutting and paste defined tables

Posted on 2011-02-24
6
245 Views
Last Modified: 2012-05-11
Dear Experts:

I got several defined tables (named Table1, Table2, Table3, etc.) in Sheet1.

Is it possible to cut Table2 and paste it into Sheet2, cut Table3 and paste it into Sheet3 and so forth?

I have attached a sample file for your convenience with detailed explanations.

Help is much appreciated. Thank you very much in advance.

Regards, Andreas

 Cut-And-Paste-Defined-Tables.xlsx
0
Comment
Question by:AndreasHermle
  • 4
  • 2
6 Comments
 
LVL 19

Accepted Solution

by:
akoster earned 500 total points
ID: 34969455
This should do the trick :
Sub process_tables()
Dim x As Integer

    For x = 2 To 4
        Range("Tabelle" & x).Cut
        On Error GoTo add_sheet
        Worksheets("Sheet" & x).Paste
        On Error GoTo 0
    Next x
        
    Exit Sub

add_sheet:
    With Worksheets.Add
        .Name = "Sheet" & x
    End With
    Resume
    
End Sub

Open in new window

0
 

Author Comment

by:AndreasHermle
ID: 34970477
Dear akoster:

thank you very much for your swift reponse. It worked once, not a second time, strange. I keep on trying and let you know.

Thank you very much.

Regards, Andreas
0
 

Author Comment

by:AndreasHermle
ID: 34977435
Hi akoster,

yes it is working. Thank you very much. There is one thing to complement the  macro. I formatted all these lists as tables (ListObject in VBA).

If the macro could first check the number of List Objects found on the current worksheet. This would then automatically determine the second integer on line 4, i.e. For x = 2 To Number of ListObjects.

What do you think? Is this possible?

Regards, Andreas
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

Author Comment

by:AndreasHermle
ID: 34977745

Hi akoster,

found out myself how to count ListObjects (lists formatted as table) in the current worksheet. (see attached code)

Regards, Andreas
Sub FindAllTablesOnSheet()
Dim j As Integer
    Dim oSh As Worksheet
    Dim oLo As ListObject
    Set oSh = ActiveSheet
    For Each oLo In oSh.ListObjects
    j = j + 1
    Next
   MsgBox j
   
End Sub

Open in new window

0
 
LVL 19

Assisted Solution

by:akoster
akoster earned 500 total points
ID: 35016361
excellent !

although the same result can be achieved faster and with less code by simply using

j = osh.listobjects.count


0
 

Author Closing Comment

by:AndreasHermle
ID: 35019341
Dear akoster:

thank you very much for your great help.

Regards, Andreas
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction This Article is a follow-up to my Mappit! Addin Article (http://www.experts-exchange.com/A_2613.html), it was inspired by an email posting I made to EUSPRIG (http://www.eusprig.org/index.htm), I will briefly cover: 1) An overvie…
This article descibes how to create a connection between Excel and SAP and how to move data from Excel to SAP or the other way around.
The viewer will learn how to simulate a series of sales calls dependent on a single skill level and learn how to simulate a series of sales calls dependent on two skill levels. Simulating Independent Sales Calls: Enter .75 into cell C2 – “skill leve…
This Micro Tutorial will demonstrate how to create pivot charts out of a data set. I also added a drop-down menu which allows to choose from different categories in the data set and the chart will automatically update.

896 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now