Hi
I found a strange behaviour in my vba code...
I have a non sorted table (see below). Obs the last row is ART_ID = 3.
I filter the table and use Range to select the rows wiht ART_ID = 3.
This range is sent to a Access database. The "c" is to only select 2 columns of total 5 in the table.
rng.Select >> selects all the 4 rows
rng.Copy >> copies all the 4 rows
but the c = rng... rows.count >> only count 3 rows???
WHY?!
I found a workaround , sorting the table before "Set" the rng-Range.
This works buts doesn't feels right. If I had 100 rows I would never found this error.
I found a strange behaviour in my vba code...

I have a non sorted table (see below). Obs the last row is ART_ID = 3.
Code:
ART_ID Program_ID
3 194
3 135
3 154
2 180
2 150
2 126
3 180
This range is sent to a Access database. The "c" is to only select 2 columns of total 5 in the table.
Code:
Set rng = tbl.DataBodyRange.Resize(, c).SpecialCells(xlCellTypeVisible)
rng.Select
rng.Copy Destination:=Sheets("DB").Cells(20, 15)
c = rng.SpecialCells(xlCellTypeVisible).Rows.Count
rng.Select >> selects all the 4 rows
rng.Copy >> copies all the 4 rows
but the c = rng... rows.count >> only count 3 rows???
WHY?!
I found a workaround , sorting the table before "Set" the rng-Range.
This works buts doesn't feels right. If I had 100 rows I would never found this error.
Last edited: