Visible cells not copying all visible cells

mahmed1

Well-known Member
Joined
Mar 28, 2009
Messages
2,240
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

What does custom number format of ;;; mean?
Three semi-colons will hide the value in the cell. Although most people use white font instead.

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
56,614
Office Version
  1. 365
Platform
  1. Windows
How are you calculating lRowCount?
 

mahmed1

Well-known Member
Joined
Mar 28, 2009
Messages
2,240
Office Version
  1. 365
  2. 2016
Platform
  1. Windows
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
 

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
56,614
Office Version
  1. 365
Platform
  1. Windows
Glad you sorted it & thanks for the feedback.
 

Watch MrExcel Video

Forum statistics

Threads
1,129,673
Messages
5,637,723
Members
416,981
Latest member
PLonchar

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
Top