VBA copy only visible cells and paste as values

johnbird1988

Board Regular
Joined
Oct 6, 2009
Messages
199
Hello,

I am try to copy only visible cells from and excel filtered table and paste them as values into another workbook. I would like to do this without using the clipboard but can not get the code to work.

I am trying:

Code:
Set wb = Workbooks.Open(SourceFolder & "\" & xlo)

   
    For Each sht In Sheets
    
 If sht.Name = "Report" Then
 
 srow = sht.UsedRange.Rows(sht.UsedRange.Rows.Count).Row
 scol = sht.UsedRange.Columns(sht.UsedRange.Columns.Count).Column

wb.Sheets("Report").AutoFilterMode = False

wb.Sheets("Report").Range(Cells(1, 1), Cells(srow, scol)).AutoFilter Field:=15, Criteria1:="=BIM" _
        , Operator:=xlOr, Criteria2:="=Report"

Windows(decomp).Activate

wb.Sheets("Report").Range(Cells(1, 1), Cells(srow, scol)).SpecialCells(xlCellTypeVisible).Copy ThisWorkbook.Sheets(12).Range("A1")

wb.Close False
End If
    Next sht

The code opens the file and filters the data set but does not copy and paste the data.

Any help or advise would be grateful,

Cheers

john
 

Excel Facts

Lock one reference in a formula
Need 1 part of a formula to always point to the same range? use $ signs: $V$2:$Z$99 will always point to V2:Z99, even after copying
I made a slight change:

wb.Sheets("Report").Range(Cells(1, 1), Cells(srow, scol)).SpecialCells(xlCellTypeVisible).Copy '1) Copy Data
Set Copywb = Workbooks.Add '2) Select destination workbook (I created a new wkbk for ease, you would need to ref relevant wkbk)
Range("A1").PasteSpecial xlPasteAll '3) Paste the copied data.

ok?
 
Upvote 0

Forum statistics

Threads
1,223,236
Messages
6,170,917
Members
452,366
Latest member
TePunaBloke

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