Visible cells not copying all visible cells

mahmed1

Well-known Member
Joined
Mar 28, 2009
Messages
2,302
Office Version
  1. 365
  2. 2016
Platform
  1. Windows
Hi All,

Can you please advise where im going wrong

Im trying to copy all visible cells once filtered and paste into cell A2 but i can see that its missing several missing cells when copying and pasting over but i dont know why its doing that

This is my code

Application.GoTo wsSheet2.Range("A1"), False

VBA Code:
wsSheet2.Range("A1:T1").AutoFilter Field:=15, Criteria1:="<>0"
    wsSheet2.Range("A1:T" & lRowCount).SpecialCells(xlCellTypeVisible).Offset(1).Select
    Selection.Copy
    wsSheet.Range("A2").PasteSpecial xlPasteValuesAndNumberFormats
 

Excel Facts

Why are there 1,048,576 rows in Excel?
The Excel team increased the size of the grid in 2007. There are 2^20 rows and 2^14 columns for a total of 17 billion cells.
How are you calculating lRowCount?
 
Upvote 0
Hiya - please see below how lrowcount is defined - it is actually highlighting until last row but it misses visible data in between which is total weird

I changed from
wsSheet2.Range("A1:T" & lRowCount).SpecialCells(xlCellTypeVisible).Offset(1).Select
to
wsSheet2.Range("A2:T" & lRowCount).SpecialCells(xlCellTypeVisible).Select

This seems to have worked for now but i have no clue why and why original wouldnt work and skip rows that are visible



VBA Code:
lRowCount = wsSheet2.Range("A" & wsSheet2.Rows.Count).End(xlUp).Row
    tbTable2.Resize wsSheet2.Range("A1:T" & lRowCount)
    
    wsSheet2.Columns("A:T").AutoFit
    wsSheet2.Range("A:A").NumberFormat = "DD/MM/YYYY"
    
    Application.GoTo wsSheet2.Range("A1"), False
    wsSheet2.Range("A1:T1").AutoFilter Field:=15, Criteria1:="<>0"
    wsSheet2.Range("A2:T" & lRowCount).SpecialCells(xlCellTypeVisible).Select
    Selection.Copy
 
Upvote 0
Glad you sorted it & thanks for the feedback.
 
Upvote 0

Forum statistics

Threads
1,214,943
Messages
6,122,369
Members
449,080
Latest member
Armadillos

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