ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   How to count optionbuttons on specific range on worksheet (https://www.excelbanter.com/excel-programming/362091-how-count-optionbuttons-specific-range-worksheet.html)

sam[_8_]

How to count optionbuttons on specific range on worksheet
 
HI,

I know the method to count the option buttons(From form toolbar) on one
worksheet as follow:

Worksheets("Sheet 1").OptionButtons.Count

Now, I want to count option buttons on specific range on worksheet,
like range"D10:F15"

I used the following code:

Worksheets("Sheet 1").range("D10:F15").OptionButtons.Count

However, it doesn't work.

Do you have some ideas about this issue? which clause should I use?
Thank you inadvance!!!


Best Regards

Sam


Norman Jones

How to count optionbuttons on specific range on worksheet
 
Hi Sam,

Try:

'=============
Public Sub Tester()
Dim rng As Range
Dim OP As OptionButton
Dim iCtr As Long

Set rng = Range("D1:F15")
For Each OP In ActiveSheet.OptionButtons
If Not Intersect(OP.TopLeftCell, rng) Is Nothing Then
iCtr = iCtr + 1
End If
Next OP

MsgBox iCtr

End Sub
'<<=============


--
---
Regards,
Norman



"sam" wrote in message
oups.com...
HI,

I know the method to count the option buttons(From form toolbar) on one
worksheet as follow:

Worksheets("Sheet 1").OptionButtons.Count

Now, I want to count option buttons on specific range on worksheet,
like range"D10:F15"

I used the following code:

Worksheets("Sheet 1").range("D10:F15").OptionButtons.Count

However, it doesn't work.

Do you have some ideas about this issue? which clause should I use?
Thank you inadvance!!!


Best Regards

Sam




Tom Ogilvy

How to count optionbuttons on specific range on worksheet
 
A suggested enhancement to Norman's idea

Dim rng1 as Range

For Each OP In ActiveSheet.OptionButtons
set rng1 = Range(OP.TopLeftCell,OP.BottomRightCell)
If Not Intersect(rng1, rng) Is Nothing Then

Depends on what you consider to be within that range.

--
Regards,
Tom Ogilvy




"Norman Jones" wrote:

Hi Sam,

Try:

'=============
Public Sub Tester()
Dim rng As Range
Dim OP As OptionButton
Dim iCtr As Long

Set rng = Range("D1:F15")
For Each OP In ActiveSheet.OptionButtons
If Not Intersect(OP.TopLeftCell, rng) Is Nothing Then
iCtr = iCtr + 1
End If
Next OP

MsgBox iCtr

End Sub
'<<=============


--
---
Regards,
Norman



"sam" wrote in message
oups.com...
HI,

I know the method to count the option buttons(From form toolbar) on one
worksheet as follow:

Worksheets("Sheet 1").OptionButtons.Count

Now, I want to count option buttons on specific range on worksheet,
like range"D10:F15"

I used the following code:

Worksheets("Sheet 1").range("D10:F15").OptionButtons.Count

However, it doesn't work.

Do you have some ideas about this issue? which clause should I use?
Thank you inadvance!!!


Best Regards

Sam





Norman Jones

How to count optionbuttons on specific range on worksheet
 
Hi Tom,

A suggested enhancement to Norman's idea


set rng1 = Range(OP.TopLeftCell,OP.BottomRightCell)


Depends on what you consider to be within that range.


A distinct enhancement - and I like it!


---
Regards,
Norman




All times are GMT +1. The time now is 05:26 PM.

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