VBA looping through workbook to copy a range and combine

StillUnderstanding

New Member
Joined
Jan 30, 2021
Messages
37
Office Version
  1. 365
Platform
  1. Windows
  2. MacOS
Hi Everyone,

I wonder if you can help me with the VBA below, I want it to loop through the workbook (Excluding the sheets mentioned) then delete 2 columns (e and F) from what is returned.

My issue is that it's only doing the last sheet.

Would someone be able to help me with this please?


VBA Code:
Sub Availability()
Dim ws As Worksheet

Application.ScreenUpdating = False
Sheets("Summary").Activate
Range("A2:g1000").Select
  
    Application.CutCopyMode = False
    Selection.ClearFormats
    Selection.Clear
For Each ws In Worksheets
If ws.Name <> "Summary" And ws.Name <> "Lookup" And ws.Name <> "Index" Then

ws.Range("b2:g3").Copy
Worksheets("Summary").Cells(Rows.Count, 1).End(xlUp).Offset(1, 1).PasteSpecial (xlPasteValues)
  ws.Range("b2:g3").Copy
Worksheets("Summary").Cells(Rows.Count, 1).End(xlUp).Offset(1, 1).PasteSpecial (xlPasteFormats)



 
End If
Next ws


Sheets("Summary").Activate
Range("e2:f1000").Select
Selection.Delete

End Sub
 
Last edited by a moderator:

Some videos you may like

Excel Facts

How to fill five years of quarters?
Type 1Q-2023 in a cell. Grab the fill handle and drag down or right. After 4Q-2023, Excel will jump to 1Q-2024. Dash can be any character.

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
55,410
Office Version
  1. 365
Platform
  1. Windows
How about
VBA Code:
   If Ws.Name <> "Summary" And Ws.Name <> "Lookup" And Ws.Name <> "Index" Then
      Ws.Range("b2:g3").Copy
      With Worksheets("Summary").Cells(Rows.Count, 2).End(xlUp).Offset(1)
         .PasteSpecial xlPasteValues
         .PasteSpecial xlPasteFormats
      End With
   End If
 
Solution

Watch MrExcel Video

Forum statistics

Threads
1,127,313
Messages
5,623,932
Members
416,001
Latest member
teabag

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
Top