Efficient Way to Append Rows from one table to another?

PC_Meister

Board Regular
Joined
Aug 28, 2013
Messages
72
Hello,

I have a workbook with two tables. Table1 and Table2 have certain columns with the same header (but in totally different order). What I would like to do is append rows that are in Table2 into Table1 (the columns that are in Table1 but not in Table2 will be blank). The one way I am thinking about is using SQL but I am thinking there must be a faster way in Excel. Any thoughts? Thanks in advance
 
My bad, I was going from memory and did not test. The correct line should be:

Rich (BB code):
dim calcs as Excel.XlCalculation
 
Upvote 0
I was able to try this yesterday afternoon. It still did not work. However, in my troubleshooting, I re-ran it in another workbook where it worked before. It still worked. Try to run it for a different zip code and it stalls at the second On Error goto 0

Code:
 For Each wshInput In wshOurWorkbook.Worksheets
      iMatch = 0
      
      On Error Resume Next
        ' Check to see whether the current sheet is in the Exclusion List.
        If bExclude Then
          iMatch = Application.WorksheetFunction.Match(wshInput.Name, rngExclusionList, 0)
        End If
        ' Additionally, check for Exclusion List and Output sheet.
        iMatch = (iMatch <> 0) Or (StrComp(wshInput.Name, sOUTPUT_SHEET) = 0) Or (StrComp(wshInput.Name, sEXCLUSION_LIST) = 0)
      On Error GoTo 0
      
      ' If nothing matched, then we proceed.
      If Not iMatch Then
        With wshInput
          Set rngInputHeaders = .Range(.Range("A1"), .Range("XFD1").End(xlToLeft))
        End With

Question 1: Does it matter if you export/import a macro from one workbook to another vs copying it to notepad and then copying it to the new workbook?

Question 2: Does it matter if more than one workbook is open? How about if it is in a different session of Excel?

Question 3: Is there any easy way to put the macros that I know are working into a Personal Macros workbook so they are accessible from new workbooks?

Thank you,
 
Upvote 0
"On Error GoTo 0" is a very strange place to stall. It is a very straightforward command. Is this stalling accompanied by a message of any kind?

Regarding your other questions:
1. Exporting a module and editing with a text editor (e.g. Notepad) allows you to see some VB module properties at the top that VBA otherwise hides. Unless you are changing one of those (for example, setting default property in a class module), there would be no difference between import/export and copy/paste. You can also drag and drop, by the way.

2. For the purposes of this macro, it shouldn't matter. However, more workbooks may affect performance. Separate instances is usually OK in general.

3. In general, when you're converting to a general-purpose macro, you will need to make some changes. For example, ThisWorkbook would become ActiveWorkbook. You would also use ActiveSheet, ActiveCell, Selection, and so on to work with whatever is in front of you. In some more complex scenarios, you might have to create additional procedures to look for specific components of a given workbook, as well as check to make sure whatever is currently in front of you. Often enough, such adaptation is simple (you see it in form of utility/toolkit type applications), but it is a case-by-case basis process.

Hope that helps?
 
Upvote 0
Thank you. I am still working on it. For whatever reason it did not want to work in that specific workbook so I'm starting fresh. Apparently something got corrupted or I copied the wrong version of the macro. I'm trying to make a "template" workbook with all macros it in that can be used for any zip code.

Thank you again. Will let you know if I have any further questions.
 
Upvote 0

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top