#1   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 52
Default How to end IF THEN

I have 2 macros, partially copied below, which are not working out.
What they are supposed to do is....if an entire row is not selcted, you get
the message box, but if one does select the entire row, there would be no
message box, and the selected entire row would be cut, and the procedure
would continue.

What is happening is that the message box comes up fine when only a cell is
selected, but I still get the message box when the entire row is selected,
and the macro doesn't proceed.

What am I leaving out? It's like I can't turn the IF THEN "off". I'm sure
it's something very simple.



If TypeName(Selection) < "entirerow" Then
MsgBox "MUST SELECT ENTIRE ROW"
Exit Sub
End If
Selection.Cut .....etc.....

or.....

If ActiveCell.Select < EntireRow Then
MsgBox "MUST SELECT ENTIRE ROW"
Exit Sub
End If

ActiveCell.Select = EntireRow
EntireRow.Cut..........etc.


  #2   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 10,593
Default How to end IF THEN

Try this

If Selection.columns.count < Columns.Count Then
MsgBox "MUST SELECT ENTIRE ROW"
Exit Sub
End If


--
HTH

Bob

(there's no email, no snail mail, but somewhere should be gmail in my addy)

"carrera" wrote in message
...
I have 2 macros, partially copied below, which are not working out.
What they are supposed to do is....if an entire row is not selcted, you
get
the message box, but if one does select the entire row, there would be no
message box, and the selected entire row would be cut, and the procedure
would continue.

What is happening is that the message box comes up fine when only a cell
is
selected, but I still get the message box when the entire row is selected,
and the macro doesn't proceed.

What am I leaving out? It's like I can't turn the IF THEN "off". I'm sure
it's something very simple.



If TypeName(Selection) < "entirerow" Then
MsgBox "MUST SELECT ENTIRE ROW"
Exit Sub
End If
Selection.Cut .....etc.....

or.....

If ActiveCell.Select < EntireRow Then
MsgBox "MUST SELECT ENTIRE ROW"
Exit Sub
End If

ActiveCell.Select = EntireRow
EntireRow.Cut..........etc.




  #3   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 35,218
Default How to end IF THEN

If selection.address < activecell.entirerow.address then
msgbox "Please select the entirerow
exit sub
end if

Another way may be to just use the entire row of the activecell. And don't
bother the user:

Activecell.entirerow.cut
(for instance)


carrera wrote:

I have 2 macros, partially copied below, which are not working out.
What they are supposed to do is....if an entire row is not selcted, you get
the message box, but if one does select the entire row, there would be no
message box, and the selected entire row would be cut, and the procedure
would continue.

What is happening is that the message box comes up fine when only a cell is
selected, but I still get the message box when the entire row is selected,
and the macro doesn't proceed.

What am I leaving out? It's like I can't turn the IF THEN "off". I'm sure
it's something very simple.

If TypeName(Selection) < "entirerow" Then
MsgBox "MUST SELECT ENTIRE ROW"
Exit Sub
End If
Selection.Cut .....etc.....

or.....

If ActiveCell.Select < EntireRow Then
MsgBox "MUST SELECT ENTIRE ROW"
Exit Sub
End If

ActiveCell.Select = EntireRow
EntireRow.Cut..........etc.


--

Dave Peterson
  #4   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 11,058
Default How to end IF THEN

Here is some logic to determine if an entire row is select or not:

Sub selectamatic()
With Selection
If .Rows.Count 1 Then
MsgBox ("More than one row Selected")
Exit Sub
End If
If .Count < Columns.Count Then
MsgBox ("Part of a row selected")
Else
MsgBox ("Entire row selected")
End If
End With
End Sub

--
Gary''s Student - gsnu200776


"carrera" wrote:

I have 2 macros, partially copied below, which are not working out.
What they are supposed to do is....if an entire row is not selcted, you get
the message box, but if one does select the entire row, there would be no
message box, and the selected entire row would be cut, and the procedure
would continue.

What is happening is that the message box comes up fine when only a cell is
selected, but I still get the message box when the entire row is selected,
and the macro doesn't proceed.

What am I leaving out? It's like I can't turn the IF THEN "off". I'm sure
it's something very simple.



If TypeName(Selection) < "entirerow" Then
MsgBox "MUST SELECT ENTIRE ROW"
Exit Sub
End If
Selection.Cut .....etc.....

or.....

If ActiveCell.Select < EntireRow Then
MsgBox "MUST SELECT ENTIRE ROW"
Exit Sub
End If

ActiveCell.Select = EntireRow
EntireRow.Cut..........etc.


  #5   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 52
Default How to end IF THEN

Thanks Bob! Perfect.

Curious, why does it state columns when you are working with rows?

"Bob Phillips" wrote:

Try this

If Selection.columns.count < Columns.Count Then
MsgBox "MUST SELECT ENTIRE ROW"
Exit Sub
End If


--
HTH

Bob

(there's no email, no snail mail, but somewhere should be gmail in my addy)

"carrera" wrote in message
...
I have 2 macros, partially copied below, which are not working out.
What they are supposed to do is....if an entire row is not selcted, you
get
the message box, but if one does select the entire row, there would be no
message box, and the selected entire row would be cut, and the procedure
would continue.

What is happening is that the message box comes up fine when only a cell
is
selected, but I still get the message box when the entire row is selected,
and the macro doesn't proceed.

What am I leaving out? It's like I can't turn the IF THEN "off". I'm sure
it's something very simple.



If TypeName(Selection) < "entirerow" Then
MsgBox "MUST SELECT ENTIRE ROW"
Exit Sub
End If
Selection.Cut .....etc.....

or.....

If ActiveCell.Select < EntireRow Then
MsgBox "MUST SELECT ENTIRE ROW"
Exit Sub
End If

ActiveCell.Select = EntireRow
EntireRow.Cut..........etc.







  #6   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 3,365
Default How to end IF THEN

Any selection is going to contain some number of columns, from one to the
maximum number of columns for the version of Excel in use. So by counting
the number of columns involved with a selection and comparing that to the
total possible number of columns, you determine if the entire row (or several
rows) are selected. See Gary''s Student post below to see how to test how
many rows are involved in the selection - you may not want to delete the
selection if more than one row is selected?

"carrera" wrote:

Thanks Bob! Perfect.

Curious, why does it state columns when you are working with rows?

"Bob Phillips" wrote:

Try this

If Selection.columns.count < Columns.Count Then
MsgBox "MUST SELECT ENTIRE ROW"
Exit Sub
End If


--
HTH

Bob

(there's no email, no snail mail, but somewhere should be gmail in my addy)

"carrera" wrote in message
...
I have 2 macros, partially copied below, which are not working out.
What they are supposed to do is....if an entire row is not selcted, you
get
the message box, but if one does select the entire row, there would be no
message box, and the selected entire row would be cut, and the procedure
would continue.

What is happening is that the message box comes up fine when only a cell
is
selected, but I still get the message box when the entire row is selected,
and the macro doesn't proceed.

What am I leaving out? It's like I can't turn the IF THEN "off". I'm sure
it's something very simple.



If TypeName(Selection) < "entirerow" Then
MsgBox "MUST SELECT ENTIRE ROW"
Exit Sub
End If
Selection.Cut .....etc.....

or.....

If ActiveCell.Select < EntireRow Then
MsgBox "MUST SELECT ENTIRE ROW"
Exit Sub
End If

ActiveCell.Select = EntireRow
EntireRow.Cut..........etc.





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



All times are GMT +1. The time now is 04:58 PM.

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"