ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Object Type of a selection... counting rows in a selection (https://www.excelbanter.com/excel-programming/338021-object-type-selection-counting-rows-selection.html)

Acid-Sky[_2_]

Object Type of a selection... counting rows in a selection
 

I have the following code:


Code
-------------------

Dim numPet As Integer
Dim sel ' what kind of object is this... so i can use count... "range", "application.selection" don't work

Worksheets("Datos").Activate
sel = Excel.Range("A4", Excel.Range("A4").End(xlDown)).Select

numPet = sel.Rows.Count

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


and I need to count the number of rows selected. as there will be n
blank cells
counting like this should be fine. but i don't know what kind of objec
"sel" needs to be.

btw. any idea on how to apply a filter (select only cell containing
certain string) on the selection

--
Acid-Sk
-----------------------------------------------------------------------
Acid-Sky's Profile: http://www.excelforum.com/member.php...fo&userid=2650
View this thread: http://www.excelforum.com/showthread.php?threadid=39806


Executor

Object Type of a selection... counting rows in a selection
 
Hi Acid-Sky

I am using code like

Dim iRows As Integer

Worksheets("Datos").Activate
iRows = Excel.Range("A4", Excel.Range("A4").End(xlDown)).Rows.Count

to count the number of rows.

If you would like to do something with this range try

Dim rPart As Range
Dim iRows As Integer

Worksheets("Datos").Activate
rPart = Excel.Range("A4", Excel.Range("A4").End(xlDown))
iRows = rPart.Rows.Count

I hoop this is the answer


instruite[_3_]

Object Type of a selection... counting rows in a selection
 

This code works

Code:
--------------------

Sub count()

Dim numPet As Integer
Dim sel As Range
' what kind of object is this... so i can use count... "range", "application.selection" don't work

Worksheets("Datos").Activate

Set sel = Excel.Range("A4", Excel.Range("A4").End(xlDown))

numPet = sel.Rows.count

End Sub

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


--
instruite

I am B.E. Instrumentation and Control and write now working as Hardware
design engineer in automotive electrconics industry
------------------------------------------------------------------------
instruite's Profile: http://www.excelforum.com/member.php...o&userid=26539
View this thread: http://www.excelforum.com/showthread...hreadid=398066


Executor

Object Type of a selection... counting rows in a selection
 
Hi Acid-Sky


I am using code like


Dim iRows As Integer


Worksheets("Datos").Activate
iRows = Excel.Range("A4",
Excel.Range("A4").End(xlDown))*.Rows.Count


to count the number of rows.


If you would like to do something with this range try


Dim rPart As Range
Dim iRows As Integer


Worksheets("Datos").Activate
Set rPart = Excel.Range("A4", Excel.Range("A4").End(xlDown))
iRows = rPart.Rows.Count

a range is a complex item in Excel so you must use the Set commend.


I hoop this is the answer



All times are GMT +1. The time now is 06:28 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com