Solved

Cutting and paste defined tables

Posted on 2011-02-24
6
244 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
What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

 

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

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

Drop Down List with Unique/Distinct Values (Part II - ComboBox or ListBox and Data Validation List Bonus!) David Miller (dlmille) Intro This article focuses on delivering unique, sorted lists to list objects (e.g., ComboBox, ListBox) and Dat…
This tutorial explains how to create a series of drop-down lists that are dependent upon prior selections to guide (“force”) the user to make the correct selection and reduce data errors within Microsoft Excel. Excel 2010 was used for this tutorial;…
The view will learn how to download and install SIMTOOLS and FORMLIST into Excel, how to use SIMTOOLS to generate a Monte Carlo simulation of 30 sales calls, and how to calculate the conditional probability based on the results of the Monte Carlo …
This Micro Tutorial will demonstrate how to use longer labels with horizontal bar charts instead of the vertical column chart.

746 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

11 Experts available now in Live!

Get 1:1 Help Now