Visual Basic Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming Languages - MoreVisual Basic Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
Get inside! Sample the range of functionality easily built with JMSL Library for Time Series Data Analysis, Heat Maps, Portfolio Optimization, Monte Carlo Simulation, Stock Price Charting and more. Download Now!
  #1  
Old July 24th, 2003, 06:44 AM
james_skeggs james_skeggs is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2003
Posts: 11 james_skeggs User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Loop to count the number of items in a column

Hi,

Please can you help. I have a spreadsheet containing a large set of data, and I want to be able to count the number of rows of data that I have using a VB script. ( I want to do this to reduce the amount of time that it takes to do calculations and vlookups etc).

Can anyone help please?

Reply With Quote
  #2  
Old July 25th, 2003, 02:25 AM
mvishak mvishak is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2003
Location: India
Posts: 3 mvishak User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Thumbs up You can find it easily

hi friend
The following program will give you the result.n will be the total record.send me a message if it works correctly.

give
txtfile.text text property = the path of the excel file

in general declaration
--------------------------------
Dim x1 As New Excel.Application

program
-----------------------------------
x1.Application.Workbooks.Open txtfile.text
With x1.Application.Workbooks(1).ActiveSheet
While .Cells(Row, 1) <> ""
n = n + 1
Wend
End With
x1.Application.Workbooks.Close
x1.Application.Quit
Set x1 = Nothing
it will work

Reply With Quote
  #3  
Old July 25th, 2003, 03:06 AM
james_skeggs james_skeggs is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2003
Posts: 11 james_skeggs User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Thanks for your help. I am not sure how to use the above code. Do you have to put it into sub things (eg. Sub Macro1(), End Sub) for example?

The result that i want is a number that i can use again within a script, and i want to be able to specify which column i am using the loop in.

I had something like this before with which had some of the following code, but i am not sure how to write it again!

------------------------------------------

Dim mycounter as counter
mycounter.clear

Range Ax.select

if Ax = non-blank, go to Ax+1
Add 1 to mycounter

Loop until selected cell is blank

then display the contents of mycounter

-------------------------------------------

Can anyone help please??

Reply With Quote
  #4  
Old July 25th, 2003, 07:47 PM
mvishak mvishak is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2003
Location: India
Posts: 3 mvishak User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Thumbs up

hi

here i have given the code below.the n value will be the result.hope this works.send me a message if this works well

code
---------------------------------------------
Sub Macro1()
Row = 1
While Cells(Row, 1) <> ""
n = n + 1
Row = Row + 1
Wend
n = n + 1
End Sub
----------------------------------------------
Best of luck

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming Languages - MoreVisual Basic Programming > Loop to count the number of items in a column


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 6 hosted by Hostway