Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8554033
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T14:47:23+00:00 2026-06-11T14:47:23+00:00

I am very new in EXCEL (especially in VBA). I try to write logic

  • 0

I am very new in EXCEL (especially in VBA). I try to write logic that:

go to all open books, if some book has sheet with name “Test”, it should take data from named range “Table” and then append it to the Table1 from sheet ALLDATA in book ALLDATABOOK. I try to write this, can someone help me?

Here is my code:

Private Sub CommandButton1_Click()
   Dim book As Object
    Dim lst As ListObject
   Dim iList As Worksheet
   For Each book In Workbooks

   For Each iList In book.Sheets
        If iList.Name = "Test" Then

        book.Sheets(iList.Name).Activate
Range("Table").Select


        End If
    Next

   Next
End Sub
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T14:47:24+00:00Added an answer on June 11, 2026 at 2:47 pm

    Try this (written for Excel 2007+, may not work for earlier versions)

    Private Sub CommandButton1_Click()
        Dim book As Workbook
        Dim lst As ListObject
        Dim iList As Worksheet
        Dim Rng As Range
    
        Dim wbAllDataBook As Workbook
        Dim shAllData As Worksheet
    
        ' Get reference to ALLDATA table
        Set wbAllDataBook = Workbooks("ALLDATABOOK.xlsm")  '<-- change to suit your file extension
        Set shAllData = wbAllDataBook.Worksheets("ALLDATA")
        Set lst = shAllData.ListObjects("Table1")
    
        For Each book In Workbooks
            ' Use error handler to avoid looping through all worksheets
            On Error Resume Next
            Set iList = book.Worksheets("Test")
            If Err.Number <> 0 Then
                ' sheet not present in book
                Err.Clear
                On Error GoTo 0
            Else
                ' If no error, iList references sheet "Test"
                On Error GoTo 0
                ' Get Reference to named range
                Set Rng = iList.[Table]
                ' Add data to row below existing data in table.  Table will auto extend
                If lst.DataBodyRange Is Nothing Then
                    ' Table is empty
                    lst.InsertRowRange.Resize(Rng.Rows.Count).Value = Rng.Value
                Else
                    With lst.DataBodyRange
                        .Rows(.Rows.Count).Offset(1, 0).Resize(Rng.Rows.Count).Value = Rng.Value
                    End With
                End If
            End If
        Next
    End Sub
    

    Update:

    To use with Excel 2003 replace

    If lst.DataBodyRange Is Nothing Then
    

    with

    If Not lst.InsertRowRange Is Nothing Then
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am very new to Excel and vba. I have an excel file that
I'm very new to Excel and VBA and was wondering if there is a
I'm very new to programming and I'm just starting to learn VBA with excel.
Hi I am very new to VBA Excel Programming. I keep getting a User-defined
All I am trying to do is Open 2 Excel Files (both Sheet1), that
Very new to working with Visual Basic / Excel. I am trying to write
I'm very new to Calc but a relative veteran with Excel. Unfortunately I don't
Very new to JQuery and MVC and webdevelopment over all. I'm now trying to
Very new to XSL (and XML for that matter), but I need to step
I am getting a very weird error when using VBA in excel. I am

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.