Problem with creating range with visible cells

sharshra

Active Member
Joined
Mar 20, 2013
Messages
276
Office Version
  1. 365
I am trying to create a range with visible cells after filtering based on a criteria. But, facing some wierd problem with setting correct range with visible cells. Here is the code. Can anyone help to resolve this?
Rich (BB code):
 
xlsDynRange = xlsWorksheet.Range("A1:G500")
xlsDynRange.AutoFilter(Field:=1, Criteria1:=intEmpid)
xlsFilteredRange = xlsDynRange.Range("A1:G500").SpecialCells(Excel.XLCellType.xlCellTypeVisible).Cells
Here, xlsFilteredRange.Cells.Count returns correct values. For example, for a particular filtered criteria, if there are 6 rows, it returns 42 (6 rows * 7 columns). However, xlsFilteredRange.Rows.Count always returns 1 (header row), though there are 6 rows. How can this be fixed?
 

Excel Facts

Did you know Excel offers Filter by Selection?
Add the AutoFilter icon to the Quick Access Toolbar. Select a cell containing Apple, click AutoFilter, and you will get all rows with Apple
Perhaps

Code:
Set xlsDynRange = xlsWorksheet.Range("A1:G500")
xlsDynRange.AutoFilter Field:=1, Criteria1:=intEmpid
Set xlsFilteredRange = xlsDynRange.SpecialCells(xlCellTypeVisible)
 
Upvote 0
Still no change :(...
xlsFilteredRange.Cells.Count gives 42 but .Rows.Count shows 1 :(
BTW, I am using this in vb.net code.
 
Upvote 0

Forum statistics

Threads
1,214,812
Messages
6,121,696
Members
449,048
Latest member
81jamesacct

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