VBA to loop through all tabs in the workbook and copy-paste to another worksheet

CassieL

Board Regular
Joined
Jun 14, 2016
Messages
90
Hi all,

I have the following VBA code to loop through the tab and look for a certain value at Range("R1"), if "Y", I like to copy Range("R3") to Range("B5") of the worksheet." Overview".
However, it doesn't copy to Overview tab. Please advice. Thanks!




VBA Code:
    Dim ws As Worksheet
    Dim Summary As Worksheet

    Set Summary = ThisWorkbook.Sheets("Overview")

    For Each ws In ThisWorkbook.Sheets
        If Not ws.Name = "Overview" Then
            If ws.Range("R1").Value = "Y" Then
                Range("M3").Copy Destination:=Summary.Range("B5" & Rows.Count).End(xlUp).Offset(1, 0)
            End If
        End If
    Next ws

End Sub
 

Excel Facts

Create a Pivot Table on a Map
If your data has zip codes, postal codes, or city names, select the data and use Insert, 3D Map. (Found to right of chart icons).

uk747

Well-known Member
Joined
Jul 20, 2011
Messages
653
Office Version
  1. 365
Platform
  1. Windows
copy Range("R3") to Range("B5") of the worksheet."

Change
VBA Code:
Range("M3").Copy Destination:=Summary.Range("B5" & Rows.Count).End(xlUp).Offset(1, 0)

VBA Code:
Range("R3").Copy Destination:=Summary.Range("B5" & Rows.Count).End(xlUp).Offset(1, 0)
 
Solution

CassieL

Board Regular
Joined
Jun 14, 2016
Messages
90
@uk747 Thanks for your comment. I think I found the issue, I still got an error after changing the range to R3, but when I change from "B5" to "B", it works.

Question, how to paste as value as it is currently paste as formula.

VBA Code:
Range("R3").Copy Destination:=Summary.Range("B" & Rows.Count).End(xlUp).Offset(1, 0)
 

uk747

Well-known Member
Joined
Jul 20, 2011
Messages
653
Office Version
  1. 365
Platform
  1. Windows
VBA Code:
Range("R3").Copy Destination:=Summary.Range("B" & Rows.Count).End(xlUp).Offset(1, 0).PasteSpecial xlPasteValues
 

CassieL

Board Regular
Joined
Jun 14, 2016
Messages
90

ADVERTISEMENT

@uk747, I tried, but I got an error

VBA Code:
Compile error: syntax error
 

uk747

Well-known Member
Joined
Jul 20, 2011
Messages
653
Office Version
  1. 365
Platform
  1. Windows
Other ones

VBA Code:
xlPasteValues
xlPasteComments
xlPasteFormulas
xlPasteFormats
xlPasteAll
xlPasteValidation
xlPasteAllExceptBorders
xlPasteColumnWidths
xlPasteFormulasAndNumberFormats
xlPasteValuesAndNumberFormats
xlPasteAllUsingSourceTheme
xlPasteAllMergingConditionalFormats
 

uk747

Well-known Member
Joined
Jul 20, 2011
Messages
653
Office Version
  1. 365
Platform
  1. Windows
Try
VBA Code:
Range("R3").Copy

With Summary.Range("B" & Rows.Count).End(xlUp).Offset(1, 0)
    .PasteSpecial Paste:=xlPasteValues
End With
 
Master Excel Bundle

Excel contains over 450 functions, with more added every year. That’s a huge number, so where should you start? Right here with this bundle.

Forum statistics

Threads
1,151,770
Messages
5,766,379
Members
425,350
Latest member
procha

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