Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Cutting and paste defined tables

Posted on 2011-02-24
6
Medium Priority
?
258 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:
Arno Koster earned 2000 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
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 

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:Arno Koster
Arno Koster earned 2000 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

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

Question has a verified solution.

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

You need to know the location of the Office templates folder, so that when you create new templates, they are saved to that location, and thus are available for selection when creating new documents.  The steps to find the Templates folder path are …
This article describes how you can use Custom Document Properties to store settings and other information in your workbook so that they will be available the next time you open the workbook.
The viewer will learn how to use the =DISCRINV command to create a discrete random variable, use this command to model a set of probabilities and outcomes in a Monte Carlo simulation, and learn how to find the standard deviation of a set of probabil…
This Micro Tutorial demonstrates in Microsoft Excel how to consolidate your marketing data by creating an interactive charts using form controls. This creates cool drop-downs for viewers of your chart to choose from.

916 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