ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Detect if current select is a row (https://www.excelbanter.com/excel-programming/428637-detect-if-current-select-row.html)

Billy B

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.

Jacob Skaria

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.


Rick Rothstein

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.



Jacob Skaria

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.


Billy B

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.


Tim Zych

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.




Rick Rothstein

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.





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

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