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

Convert text numbers to real numbers
Select a column containing text numbers. Press Alt+D E F to quickly convert text to numbers. Faster than "Convert to Number"
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)
 
Upvote 0
Solution
@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)
 
Upvote 0
VBA Code:
Range("R3").Copy Destination:=Summary.Range("B" & Rows.Count).End(xlUp).Offset(1, 0).PasteSpecial xlPasteValues
 
Upvote 0
Other ones

VBA Code:
xlPasteValues
xlPasteComments
xlPasteFormulas
xlPasteFormats
xlPasteAll
xlPasteValidation
xlPasteAllExceptBorders
xlPasteColumnWidths
xlPasteFormulasAndNumberFormats
xlPasteValuesAndNumberFormats
xlPasteAllUsingSourceTheme
xlPasteAllMergingConditionalFormats
 
Upvote 0
Try
VBA Code:
Range("R3").Copy

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

Forum statistics

Threads
1,213,504
Messages
6,114,016
Members
448,543
Latest member
MartinLarkin

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