View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
GS[_6_] GS[_6_] is offline
external usenet poster
 
Posts: 1,182
Default rows.count property returns 2 even though only 1 row was imported by querytables.add

Environment:
Win7 Home Premium SP1
MS Office Home 2010
Excel 14
VBA for Applications 7.0

Importing a single-line text file with the following

Set qrytable = ActiveSheet.QueryTables.ADD(Connection:="TEXT;" + csvFile,
...)

With qrytable
.Refresh BackgroundQuery:=False
nValues = .ResultRange.Rows.Count
End With

produces nValues=2 from the Rows.Count property. If there's more than one
line in the file, Rows.Count is indeed correct.

Anyone else seen this behaviour ?


This is typical when the process writing the data to the text file doesn't
deliberately exclude the last carriage-return/linefeed. So importing as you've
done will include a blank record causing the record count to inflate by 1!

--
Garry

Free usenet access at http://www.eternal-september.org
Classic VB Users Regroup!
comp.lang.basic.visual.misc
microsoft.public.vb.general.discussion