Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 54
Default Detect if current select is a row

Is it possible to test to see if the current selection is a row? I have a
command button that is designed to delete the selected row but but I need to
test to see if it is selected before running the rest of the macro.

Thank you.
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 8,520
Default Detect if current select is a row

Use Selection.Address to check

If row 17 is selected this will return $17:$17
--
If this post helps click Yes
---------------
Jacob Skaria


"Billy B" wrote:

Is it possible to test to see if the current selection is a row? I have a
command button that is designed to delete the selected row but but I need to
test to see if it is selected before running the rest of the macro.

Thank you.

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,934
Default Detect if current select is a row

Why test if the entire row is selected when you can force the selection of
the entire row; something like this...

' Ask user to select the row as you do now, then run this code
If Selection.Columns = 1 Then
Selection.EntireRow.Select
'
' the rest of your code goes here
'
Else
MsgBox "You selected more than one row!"
End If

Although I'm willing to bet that you don't really need to perform the
selection operation as opposed to simply working with the range itself in
code.

--
Rick (MVP - Excel)


"Billy B" wrote in message
...
Is it possible to test to see if the current selection is a row? I have a
command button that is designed to delete the selected row but but I need
to
test to see if it is selected before running the rest of the macro.

Thank you.


  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 8,520
Default Detect if current select is a row

If you are looking to delete the row you can use

Rows(Selection.row).delete
--
If this post helps click Yes
---------------
Jacob Skaria


"Jacob Skaria" wrote:

Use Selection.Address to check

If row 17 is selected this will return $17:$17
--
If this post helps click Yes
---------------
Jacob Skaria


"Billy B" wrote:

Is it possible to test to see if the current selection is a row? I have a
command button that is designed to delete the selected row but but I need to
test to see if it is selected before running the rest of the macro.

Thank you.

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 54
Default Detect if current select is a row

Thank you for the help. What is really going on is the user may or may not
select the row and if the row is selected, do the procedure and if only a
cell is selected, select the row. The next reply did address that. Thanks
again.

"Jacob Skaria" wrote:

If you are looking to delete the row you can use

Rows(Selection.row).delete
--
If this post helps click Yes
---------------
Jacob Skaria


"Jacob Skaria" wrote:

Use Selection.Address to check

If row 17 is selected this will return $17:$17
--
If this post helps click Yes
---------------
Jacob Skaria


"Billy B" wrote:

Is it possible to test to see if the current selection is a row? I have a
command button that is designed to delete the selected row but but I need to
test to see if it is selected before running the rest of the macro.

Thank you.



  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 389
Default Detect if current select is a row

Other options, customize depending on how much control you want to have, or
to what degree you want to flex based on the user selection.

' To accept the top left cell as the starting point, but expand to the
entire row. One row max.
Selection.Cells(1,1).EntireRow.Delete

' To allow multiple rows to be deleted at one time
Selection.EntireRow.Delete

' To force the user to re-select
With Selection
If .Rows.Count 1 Or .Columns.Count < Columns.Count Then
MsgBox "Select one row to delete from."
Else
.EntireRow.Delete
End If
End With

--
Regards,
Tim Zych
http://www.higherdata.com
Workbook Compare - Excel data comparison utility

"Billy B" wrote in message
...
Is it possible to test to see if the current selection is a row? I have a
command button that is designed to delete the selected row but but I need
to
test to see if it is selected before running the rest of the macro.

Thank you.



  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,934
Default Detect if current select is a row

If Selection.Columns = 1 Then

Of course the above should have been...

If Selection.Rows = 1 Then

--
Rick (MVP - Excel)


"Rick Rothstein" wrote in message
...
Why test if the entire row is selected when you can force the selection of
the entire row; something like this...

' Ask user to select the row as you do now, then run this code
If Selection.Columns = 1 Then
Selection.EntireRow.Select
'
' the rest of your code goes here
'
Else
MsgBox "You selected more than one row!"
End If

Although I'm willing to bet that you don't really need to perform the
selection operation as opposed to simply working with the range itself in
code.

--
Rick (MVP - Excel)


"Billy B" wrote in message
...
Is it possible to test to see if the current selection is a row? I have a
command button that is designed to delete the selected row but but I need
to
test to see if it is selected before running the rest of the macro.

Thank you.



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
how to select current sheet tab Knox Excel Programming 11 March 7th 07 01:54 PM
Select Current Row achidsey[_2_] Excel Programming 3 September 15th 06 01:39 PM
How do I detect and commit the current cell edition? [email protected] Excel Programming 5 April 11th 06 04:40 AM
how to select current range mikerr Excel Programming 4 August 4th 05 05:40 PM
How to detect current active sheet number Mike Chen Excel Programming 3 April 3rd 04 04:41 PM


All times are GMT +1. The time now is 11:56 AM.

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

About Us

"It's about Microsoft Excel"