|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
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
|
|||
|
|||
|
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? |
|
#2
|
|||
|
|||
|
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 ![]() |
|
#3
|
|||
|
|||
|
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?? |
|
#4
|
|||
|
|||
|
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 ![]() |
![]() |
| Viewing: Dev Shed Forums > Programming Languages - More > Visual Basic Programming > Loop to count the number of items in a column |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|