Code keeps pasting values over existing rows, Unable to paste value from empty row below

tarallox

New Member
Joined
May 23, 2015
Messages
7
Dear all,

I've been looking for quite a while now.. I've been trying to copy and paste VALUE from worksheets (All except TEST), into the "MasterSheet".
Other worksheets have formulas from A15 : A50 - and I'm trying to only copy and paste the values that are not " ". (i.e. if empty, move onto next worksheet and copy from a15 - a x).

i've tried using the code below so far, I can see my formulas / data come out but it's getting overwritten by the final worksheets data (meaning instead of 4 pages of work stacked, it's 1 as the rest have been deleted).

Can someone help me? Any guidance is super appreciated..

VBA Code:
Sub copypaste()


Sheets("MasterSheet").Select
Range("A20:A1000").Select
Selection.ClearContents

Dim J As Integer
Dim sh As Worksheet
Const excludeSheets As String = "test"

On Error Resume Next
For Each sh In ActiveWorkbook.Worksheets

If IsError(Application.Match(sh.Name, Split(excludeSheets, ","))) Then
        Application.GoTo Sheets(sh.Name).[b3]
        Range("A13:A50").Select
        Selection.Copy
       Worksheets("MasterSheet").Activate
    Range("a1").End(xlUp).Offset(rowOffset:=10, columnOffset:=2).PasteSpecial xlPasteValues
    End If
   
Next
Application.CutCopyMode = False
MsgBox "Master Updated"

End Sub
 
Last edited by a moderator:

Excel Facts

What is the shortcut key for Format Selection?
Ctrl+1 (the number one) will open the Format dialog for whatever is selected.
Alternatively if you think a better code can be written..

I'm trying to do this

1) Copy and paste only non " " values from worksheets (1,2,3), cells A20-A100,
2) Paste values into MasterSheet from B11 and down
 
Upvote 0
How do you want the data to show up in the MasterSheet? As a single column starting B11?
 
Upvote 0
Give this a try:
VBA Code:
Sub copypaste_mod()

    Dim arrExcludeSheets As Variant
    Dim wb As Workbook
    Dim mstrSht As Worksheet
    Dim sh As Worksheet
    Dim copyRng As Range
    Dim destRng As Range
    Dim destRngNonBlank As Range
    Dim i As Long
    Dim arr() As Variant
    Dim rCell As Range
    
    arrExcludeSheets = Array("test", "MasterSheet")
    Set wb = ThisWorkbook
    Set mstrSht = wb.Sheets("MasterSheet")
    mstrSht.Range("B11:B" & mstrSht.Cells(Rows.Count, "B").End(xlUp).Row).ClearContents
    
    On Error Resume Next
    For Each sh In wb.Worksheets
    
        If IsError(Application.Match(sh.Name, arrExcludeSheets, 0)) Then
            'Set copyRng = sh.Range("A15:A" & sh.Cells(Rows.Count, "A").End(xlUp).Rows)
            Set copyRng = sh.Range("A15:A50")
            Set destRng = mstrSht.Cells(Rows.Count, "B").End(xlUp).Offset(1)
            If destRng.Row < 11 Then Set destRng = mstrSht.Range("B11")
            destRng.Resize(copyRng.Rows.Count).Value = copyRng.Value
        End If
        
    Next
    
    Set destRng = mstrSht.Range("B11:B" & mstrSht.Cells(Rows.Count, "B").End(xlUp).Row)
    Set destRngNonBlank = destRng.SpecialCells(xlCellTypeConstants)
    
    ReDim arr(1 To destRngNonBlank.Cells.Count, 1 To 1)
    
    i = 0
    For Each rCell In destRngNonBlank
        i = i + 1
        arr(i, 1) = rCell.Value
    Next rCell
    
    destRng.ClearContents
    destRng.Resize(UBound(arr, 1)).Value = arr

    MsgBox "Master Updated"

End Sub
 
Upvote 0

Forum statistics

Threads
1,223,228
Messages
6,170,871
Members
452,363
Latest member
merico17

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