PC Review


Reply
Thread Tools Rate Thread

Detect if current select is a row

 
 
Billy B
Guest
Posts: n/a
 
      18th May 2009
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 With Quote
 
 
 
 
Jacob Skaria
Guest
Posts: n/a
 
      18th May 2009
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.

 
Reply With Quote
 
Rick Rothstein
Guest
Posts: n/a
 
      18th May 2009
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" <(E-Mail Removed)> wrote in message
news:CB40003A-16F7-44BB-9462-(E-Mail Removed)...
> 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 With Quote
 
Jacob Skaria
Guest
Posts: n/a
 
      18th May 2009
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.

 
Reply With Quote
 
Billy B
Guest
Posts: n/a
 
      18th May 2009
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.

 
Reply With Quote
 
Tim Zych
Guest
Posts: n/a
 
      18th May 2009
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" <(E-Mail Removed)> wrote in message
news:CB40003A-16F7-44BB-9462-(E-Mail Removed)...
> 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 With Quote
 
Rick Rothstein
Guest
Posts: n/a
 
      18th May 2009
> If Selection.Columns = 1 Then

Of course the above should have been...

If Selection.Rows = 1 Then

--
Rick (MVP - Excel)


"Rick Rothstein" <(E-Mail Removed)> wrote in message
news:%238AOxY%(E-Mail Removed)...
> 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" <(E-Mail Removed)> wrote in message
> news:CB40003A-16F7-44BB-9462-(E-Mail Removed)...
>> 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 With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to detect the current email address???? Emil Microsoft C# .NET 1 19th Feb 2008 10:19 AM
the proper way to detect changes to current row before moving to next row GS Microsoft C# .NET 2 1st Jan 2008 09:09 AM
How can I detect the current SetWarnings setting? A C Microsoft Access VBA Modules 6 28th Sep 2005 02:06 PM
Detect Current Record Locking =?Utf-8?B?TURX?= Microsoft Access VBA Modules 1 20th Apr 2005 07:14 AM
How to detect if the current process (or dll) run as service ??? Thierry Microsoft Dot NET 2 19th Oct 2003 10:23 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 03:43 AM.