ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   How do I check the number of rows selected (https://www.excelbanter.com/excel-programming/369695-how-do-i-check-number-rows-selected.html)

[email protected]

How do I check the number of rows selected
 
Hi,

My sheet has about 30 rows. I want the user to select only one row and
that row gets copied to a new sheet.

The Code to let the user select the row is

Set rng = Application.InputBox(prompt:="Select Column to Work on",
Type:=8)
rng.Select

How do I make sure the sure only one row is selected?

If more than one row is selected I need to display an error message.

Thanks


Gary Keramidas

How do I check the number of rows selected
 
something like this

Sub test()
If Selection.Rows.Count 1 Then
MsgBox "please select only 1 row"
Else
'your code
End If

End Sub

--


Gary


"NickHK" wrote in message
...
If rng.Rows.count 1 then
MsgbOx "Single row only"
...etc

However, you Input Prompt is somewhat confusing. Instead of "Select Column
to Work on", use "Select a single row".

NickHK

wrote in message
oups.com...
Hi,

My sheet has about 30 rows. I want the user to select only one row and
that row gets copied to a new sheet.

The Code to let the user select the row is

Set rng = Application.InputBox(prompt:="Select Column to Work on",
Type:=8)
rng.Select

How do I make sure the sure only one row is selected?

If more than one row is selected I need to display an error message.

Thanks






NickHK

How do I check the number of rows selected
 
If rng.Rows.count 1 then
MsgbOx "Single row only"
....etc

However, you Input Prompt is somewhat confusing. Instead of "Select Column
to Work on", use "Select a single row".

NickHK

wrote in message
oups.com...
Hi,

My sheet has about 30 rows. I want the user to select only one row and
that row gets copied to a new sheet.

The Code to let the user select the row is

Set rng = Application.InputBox(prompt:="Select Column to Work on",
Type:=8)
rng.Select

How do I make sure the sure only one row is selected?

If more than one row is selected I need to display an error message.

Thanks




[email protected]

How do I check the number of rows selected
 
Gary & NickHK,

Thanks for you help. It worked.

Dhruba

Gary Keramidas wrote:
something like this

Sub test()
If Selection.Rows.Count 1 Then
MsgBox "please select only 1 row"
Else
'your code
End If

End Sub

--


Gary


"NickHK" wrote in message
...
If rng.Rows.count 1 then
MsgbOx "Single row only"
...etc

However, you Input Prompt is somewhat confusing. Instead of "Select Column
to Work on", use "Select a single row".

NickHK

wrote in message
oups.com...
Hi,

My sheet has about 30 rows. I want the user to select only one row and
that row gets copied to a new sheet.

The Code to let the user select the row is

Set rng = Application.InputBox(prompt:="Select Column to Work on",
Type:=8)
rng.Select

How do I make sure the sure only one row is selected?

If more than one row is selected I need to display an error message.

Thanks





Dave Peterson

How do I check the number of rows selected
 
Or just use the top row of any selection:

Set rng = Application.InputBox(prompt:="Select a Row to Work on", _
Type:=8).rows(1)

rng.select

wrote:

Hi,

My sheet has about 30 rows. I want the user to select only one row and
that row gets copied to a new sheet.

The Code to let the user select the row is

Set rng = Application.InputBox(prompt:="Select Column to Work on",
Type:=8)
rng.Select

How do I make sure the sure only one row is selected?

If more than one row is selected I need to display an error message.

Thanks


--

Dave Peterson


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

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