Copy Only Cells From Visible Sheets And Paste Into Next Free Column VBA

Dante Smith

I have a VBA code that is currently running where it is coping cell (C2: C3) from all sheets and is pasting in the "Master" sheet. The issue that I have is that I want it to only copy the visible sheets as some of my hidden sheets have different data running my sheets. I also have an issue of it pasting in the next row and I want it to paste in the next column and can't figure it out :/.

 Option Explicit

Sub Sample()
Dim wsInput As Worksheet, wsOutput As Worksheet
Dim rng As Range
Dim LRowO As Long, LRowI As Long
Set wsOutput = ThisWorkbook.Sheets("Master")
For Each wsInput In ThisWorkbook.Worksheets
    If wsInput.Name <> wsOutput.Name Then
        With wsInput
            Set rng = .Range("C2:C3")
            rng.Copy
            With wsOutput
                LRowO = .Range("A" & .Rows.Count).End(xlUp).Row + 1
                .Range("A" & LRowO).PasteSpecial xlPasteValues, _
                Operation:=xlNone, SkipBlanks:=False, Transpose:=False
            End With
        End With
    End If
Next wsInput

Exit Sub

 End Sub
Matt Cremeens

Sounds like you need to check if the worksheet is hidden and also keep track of what the next column would be and increment it each time you paste into it. Here is your code modified for both of those things

 Option Explicit

Sub Sample()
Dim wsInput As Worksheet, wsOutput As Worksheet
Dim rng As Range
LRowI As Long
Dim nextCol as Long
Set wsOutput = ThisWorkbook.Sheets("Master")
nextCol = 1
For Each wsInput In ThisWorkbook.Worksheets
    If wsInput.Name <> wsOutput.Name and wsInput.Visible = True Then
        With wsInput
            Set rng = .Range("C2:C3")
            rng.Copy
            With wsOutput
                .Cells(1, nextCol).PasteSpecial xlPasteValues, _
                Operation:=xlNone, SkipBlanks:=False, Transpose:=False
                nextCol = nextCol + 1
            End With
        End With
    End If
Next wsInput

Exit Sub

 End Sub

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Excel VBA - Paste to visible cells

From Dev

VBA Copy & Paste only selecting 2 cells based on active sheet

From Dev

Excel VBA Copy & Paste a Range of Cells Repeatedly in a Column

From Dev

Excel - VBA Loop - Copy formulas from cells, paste into cells, then copy paste special

From Dev

Copy/Paste only cells with values

From Dev

VBA code to copy cells in specific column and paste (value) it to cells in specific column on another Sheet based on conditions

From Dev

vba code to select only visible cells in specific column except heading

From Dev

How to copy only visible cells from workbook to workbook?

From Dev

Copy and Paste a Column only if data is present above it (Such as a name) in Excel VBA

From Dev

VBA: Copy cells, paste as a picture, then save as a picture?

From Dev

Copy and Paste a Range of Cells using VBA

From Dev

Excel vba macro to copy cells and paste in another

From Dev

Macro to copy and paste as values only the active cells

From Dev

vba copy values in different sheets and cells

From Dev

copy and paste next without for vba error

From Dev

VBscript: Copy/Paste data from one workbook to next blank row (specific cells) of another workbook

From Dev

Excel VBA, How to copy cells from within a Column object

From Dev

vba excel copy only visible cells on key press ctrl+c for protected sheet

From Dev

range.cells.copy to range.cells.paste in vba

From Dev

Copying only the visible cells from visible worksheets into a new workbook, excel 2007 VBA

From Dev

Copy from multiple sheets and paste into sheet 1

From Dev

Excel VBA - Copy range from one sheet paste to all sheets after certain sheet in workbook

From Dev

VBA copying visible cells only issues

From Dev

VBA Excel: Show visible cells in listbox only

From Dev

excel vba macro to match cells from two different workbooks and copy and paste accordingly

From Dev

excel vba macro to match cells from two different workbooks and copy and paste accordingly

From Dev

VBA Copy Paste Values From Separate Ranges And Paste On Same Sheet, Same Row Offset Columns (Repeat For Multiple Sheets)

From Dev

How to copy the values from the same column into the next columns? Excel VBA

From Dev

Sum only visible cells in one ROW (not column)?

Related Related

  1. 1

    Excel VBA - Paste to visible cells

  2. 2

    VBA Copy & Paste only selecting 2 cells based on active sheet

  3. 3

    Excel VBA Copy & Paste a Range of Cells Repeatedly in a Column

  4. 4

    Excel - VBA Loop - Copy formulas from cells, paste into cells, then copy paste special

  5. 5

    Copy/Paste only cells with values

  6. 6

    VBA code to copy cells in specific column and paste (value) it to cells in specific column on another Sheet based on conditions

  7. 7

    vba code to select only visible cells in specific column except heading

  8. 8

    How to copy only visible cells from workbook to workbook?

  9. 9

    Copy and Paste a Column only if data is present above it (Such as a name) in Excel VBA

  10. 10

    VBA: Copy cells, paste as a picture, then save as a picture?

  11. 11

    Copy and Paste a Range of Cells using VBA

  12. 12

    Excel vba macro to copy cells and paste in another

  13. 13

    Macro to copy and paste as values only the active cells

  14. 14

    vba copy values in different sheets and cells

  15. 15

    copy and paste next without for vba error

  16. 16

    VBscript: Copy/Paste data from one workbook to next blank row (specific cells) of another workbook

  17. 17

    Excel VBA, How to copy cells from within a Column object

  18. 18

    vba excel copy only visible cells on key press ctrl+c for protected sheet

  19. 19

    range.cells.copy to range.cells.paste in vba

  20. 20

    Copying only the visible cells from visible worksheets into a new workbook, excel 2007 VBA

  21. 21

    Copy from multiple sheets and paste into sheet 1

  22. 22

    Excel VBA - Copy range from one sheet paste to all sheets after certain sheet in workbook

  23. 23

    VBA copying visible cells only issues

  24. 24

    VBA Excel: Show visible cells in listbox only

  25. 25

    excel vba macro to match cells from two different workbooks and copy and paste accordingly

  26. 26

    excel vba macro to match cells from two different workbooks and copy and paste accordingly

  27. 27

    VBA Copy Paste Values From Separate Ranges And Paste On Same Sheet, Same Row Offset Columns (Repeat For Multiple Sheets)

  28. 28

    How to copy the values from the same column into the next columns? Excel VBA

  29. 29

    Sum only visible cells in one ROW (not column)?

HotTag

Archive