Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 573
Default Test to see if selected range is single row?

I have a macro that asks the user to highlight the first row of data
in the worksheet so it can find and separate the worksheet into
several smaller sheets based on the identifier in the first column. I
want to be sure that the user has only selected a single row in the
input box before the rest of the macro executes. I could write code to
get the row number for the top row of the selected range and the row
number for the last row in the selected range and compare them, but
this seems more complicated than it needs to be. Is there an easier
way? Some kind of simple IF statement that tells the user to try again
if there's more than one row in their selection?

Thanks!

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,452
Default Test to see if selected range is single row?

If Selection.Rows.Count 1 Then

RBS

"davegb" wrote in message
ups.com...
I have a macro that asks the user to highlight the first row of data
in the worksheet so it can find and separate the worksheet into
several smaller sheets based on the identifier in the first column. I
want to be sure that the user has only selected a single row in the
input box before the rest of the macro executes. I could write code to
get the row number for the top row of the selected range and the row
number for the last row in the selected range and compare them, but
this seems more complicated than it needs to be. Is there an easier
way? Some kind of simple IF statement that tells the user to try again
if there's more than one row in their selection?

Thanks!


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 573
Default Test to see if selected range is single row?

On Mar 19, 1:36 pm, "RB Smissaert"
wrote:
If Selection.Rows.Count 1 Then

RBS

"davegb" wrote in message

ups.com...


Works great, Thanks!



I have a macro that asks the user to highlight the first row of data
in the worksheet so it can find and separate the worksheet into
several smaller sheets based on the identifier in the first column. I
want to be sure that the user has only selected a single row in the
input box before the rest of the macro executes. I could write code to
get the row number for the top row of the selected range and the row
number for the last row in the selected range and compare them, but
this seems more complicated than it needs to be. Is there an easier
way? Some kind of simple IF statement that tells the user to try again
if there's more than one row in their selection?


Thanks!- Hide quoted text -


- Show quoted text -



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 43
Default Test to see if selected range is single row?

If Selection.Rows.Count1 or Selection.Areas.Count1 then
HTH, James
"davegb" wrote in message
ups.com...
I have a macro that asks the user to highlight the first row of data
in the worksheet so it can find and separate the worksheet into
several smaller sheets based on the identifier in the first column. I
want to be sure that the user has only selected a single row in the
input box before the rest of the macro executes. I could write code to
get the row number for the top row of the selected range and the row
number for the last row in the selected range and compare them, but
this seems more complicated than it needs to be. Is there an easier
way? Some kind of simple IF statement that tells the user to try again
if there's more than one row in their selection?

Thanks!



  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 857
Default Test to see if selected range is single row?

If selection.Rows.Count1 then
Msgbox "Select only one row"
Else
'process the selected row
End if


--

Hope that helps.

Vergel Adriano


"davegb" wrote:

I have a macro that asks the user to highlight the first row of data
in the worksheet so it can find and separate the worksheet into
several smaller sheets based on the identifier in the first column. I
want to be sure that the user has only selected a single row in the
input box before the rest of the macro executes. I could write code to
get the row number for the top row of the selected range and the row
number for the last row in the selected range and compare them, but
this seems more complicated than it needs to be. Is there an easier
way? Some kind of simple IF statement that tells the user to try again
if there's more than one row in their selection?

Thanks!




  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Test to see if selected range is single row?

Instead of yelling at the user if he/she selected a range with multiple rows,
you could just take the top row:

dim myRng as range
set myrng = nothing
on error resume next
set myrng _
= application.inputbox(Prompt:="select a range",type:=8).areas(1).rows(1)
on error goto 0
if myrng is nothing then
'user hit cancel
else
'do what you want
end if

Or just the first cell -- or the entire row of the first cell -- or anything you
want.

davegb wrote:

I have a macro that asks the user to highlight the first row of data
in the worksheet so it can find and separate the worksheet into
several smaller sheets based on the identifier in the first column. I
want to be sure that the user has only selected a single row in the
input box before the rest of the macro executes. I could write code to
get the row number for the top row of the selected range and the row
number for the last row in the selected range and compare them, but
this seems more complicated than it needs to be. Is there an easier
way? Some kind of simple IF statement that tells the user to try again
if there's more than one row in their selection?

Thanks!


--

Dave Peterson
  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 573
Default Test to see if selected range is single row?

On Mar 19, 2:10 pm, Dave Peterson wrote:
Instead of yelling at the user if he/she selected a range with multiple rows,
you could just take the top row:


Actually, I wasn't going to yell at them... :)

Interesting point. I just need to know that the word "Adams" is
somewhere in the first row of the range they selected. If not, they
need to try again. If so, we're good to go. Think I'll take your
suggestion.
Thanks, Dave!

dim myRng as range
set myrng = nothing
on error resume next
set myrng _
= application.inputbox(Prompt:="select a range",type:=8).areas(1).rows(1)
on error goto 0
if myrng is nothing then
'user hit cancel
else
'do what you want
end if

Or just the first cell -- or the entire row of the first cell -- or anything you
want.

davegb wrote:

I have a macro that asks the user to highlight the first row of data
in the worksheet so it can find and separate the worksheet into
several smaller sheets based on the identifier in the first column. I
want to be sure that the user has only selected a single row in the
input box before the rest of the macro executes. I could write code to
get the row number for the top row of the selected range and the row
number for the last row in the selected range and compare them, but
this seems more complicated than it needs to be. Is there an easier
way? Some kind of simple IF statement that tells the user to try again
if there's more than one row in their selection?


Thanks!


--

Dave Peterson



Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
why is more than one cell selected with a single click? Fivespeed56 Excel Discussion (Misc queries) 2 September 25th 09 08:14 PM
Formula that will test text conditions in a single cell Prohock Excel Worksheet Functions 10 April 4th 06 10:21 PM
Running a Macro when a single cell is selected Jerry Wustrack Excel Discussion (Misc queries) 3 January 31st 06 08:27 PM
Test for Single Character That is in an Array scallyte Excel Worksheet Functions 2 November 11th 04 04:47 PM
How can I test when any worksheet within a workbook is selected Peter McNaughton Excel Programming 2 January 29th 04 04:59 AM


All times are GMT +1. The time now is 09:44 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"