Looping through Workbooks with multiple named exceptions

AdamMalbon

New Member
Joined
Nov 7, 2018
Messages
6
Sorry if this is similar to previous posts. I can't quite find one that solves my problem. I am attempting to compile multiple daily data tables into a database containing several years of information. I want to skip my personal macro workbook, as well as the sheet I am pasting into. This code works until it hits my master workbook ("FRMC.xlsm"). It will not jump to the next open workbook, it just loops through the if statement perpetually. Code below:

Code:
Sub compileFR()


Dim wb As workbook


For Each wb In Application.Workbooks
    If wb.Name = "Personal.xlsb" Or wb.Name = "frmc.xlsm" Then
        'Do nothing
        Else
 
 
    Sheets("MASTER").Select
    
                Range("b3", Range("b3").End(xlDown).Offset(0, 12)).Select
                selection.Copy
                
                Windows("frmc.xlsm").Activate
                Range("a3").End(xlDown).Offset(1, 0).Select
                
                selection.PasteSpecial Paste:=xlPasteValues
                
                Columns("A:A").Select
                selection.NumberFormat = "m/d/yyyy"
                ActiveWorkbook.Save
                
                Columns("A:M").Select
                 ActiveSheet.Range("$A$1:$M$25795").RemoveDuplicates Columns:=Array(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13), Header:=xlYes
                
                Application.CutCopyMode = False
                
                Application.DisplayAlerts = False
                wb.Close (n)
               
                
End If
Next
End Sub
 
Thank you again for your time. I agree, I do rely too hard on the “ActiveWorkbook”, “activesheet”, “activeCell”shortcuts. Unfortunately, I fixed all of the lines you identified and I can’tget this running. The if statement is not working. It is still stepping throughall of the “else” steps when it hits the frmc.xlsm book.






I had to work around this manually to get the job done. I amstill curious what I did wrong though…



Code:
Option Explicit
Sub compileFR()

Dim wb As Workbook
Dim frmc As Workbook, master As Worksheet
Set frmc = Workbooks("frmc.xlsm")
Set master = frmc.Sheets("Master")
Set wb = ActiveWorkbook

For Each wb In Application.Workbooks
  Set wb = ActiveWorkbook
  If wb.Name = "Personal.xlsb" Or wb.Name = "frmc.xlsm" Then
  Else
 wb.Sheets("MASTER").Range("b3", Range("b3").End(xlDown).Offset(0, 12)).Copy
                
                
             master.Range("a3").End(xlDown).Offset(1, 0).PasteSpecial Paste:=xlPasteValues
                
               
              
'
                Application.CutCopyMode = False
                
                Application.DisplayAlerts = False
                wb.Close
               

End If
Next

master.Activate

End Sub
 
Upvote 0

Excel Facts

Can you sort left to right?
To sort left-to-right, use the Sort dialog box. Click Options. Choose "Sort left to right"

Forum statistics

Threads
1,224,824
Messages
6,181,187
Members
453,020
Latest member
Mohamed Magdi Tawfiq Emam

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