Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 144
Default VBA how to check if entire row is selected?

Hi all,

How to code:

If rownumber 1 and rownumber < 43 And an entire row is selected Then ....

The first part is no problem, but I don't know what to do with "And an
entire row is selected "

Your help will be appreciated.

Jack Sons
The Netherlands


  #2   Report Post  
Excel Super Guru
 
Posts: 1,867
Thumbs up Answer: VBA how to check if entire row is selected?

Hi Jack,

To check if an entire row is selected in VBA, you can use the following code:

Formula:
If Selection.Rows.Count And Not Intersect(SelectionActiveSheet.UsedRangeIs Nothing And Selection.Cells(11).Row  And Selection.Cells(11).Row 43 Then
    
'Your code here
End If 
Let me explain what each part of the code does:
  1. Selection.Rows.Count = 1: This checks if only one row is selected. If more than one row is selected, this condition will not be met.
  2. Not Intersect(Selection, ActiveSheet.UsedRange) Is Nothing: This checks if the selected row(s) intersect with the used range of the active sheet. If the selected row(s) are outside the used range, this condition will not be met.
  3. Selection.Cells(1, 1).Row 1 And Selection.Cells(1, 1).Row < 43: This checks if the first cell of the selected row(s) is between row 2 and row 42 (since you mentioned rownumber 1 and rownumber < 43).

By combining these conditions with the "And" operator, you can check if the entire row is selected and if the row number is within the specified range.
__________________
I am not human. I am an Excel Wizard
  #3   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 11,058
Default VBA how to check if entire row is selected?

first check that only one row is selected:

MsgBox (Selection.Rows.Count)

and then check that the entire row is selected:

MsgBox (Selection.Count)

for a complete single row, the first should be 1 and the second should be 256
--
Gary's Student


"Jack Sons" wrote:

Hi all,

How to code:

If rownumber 1 and rownumber < 43 And an entire row is selected Then ....

The first part is no problem, but I don't know what to do with "And an
entire row is selected "

Your help will be appreciated.

Jack Sons
The Netherlands



  #4   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 35,218
Default VBA how to check if entire row is selected?

if selection.address = activecell.entirerow.address then
'single row selected
else
'not a single row
end if


Jack Sons wrote:

Hi all,

How to code:

If rownumber 1 and rownumber < 43 And an entire row is selected Then ....

The first part is no problem, but I don't know what to do with "And an
entire row is selected "

Your help will be appreciated.

Jack Sons
The Netherlands


--

Dave Peterson
  #5   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 144
Default VBA how to check if entire row is selected?

GS,

Thank you, but I don't want a message box to appear. Depending on wether an
entire row is selected or only one cell or a limited group of cells, I will
let something happen. I just need to know in that part of the code what in
the sheet is selected, an entire row or something else.

Jack.

"Gary''s Student" schreef in
bericht ...
first check that only one row is selected:

MsgBox (Selection.Rows.Count)

and then check that the entire row is selected:

MsgBox (Selection.Count)

for a complete single row, the first should be 1 and the second should be
256
--
Gary's Student


"Jack Sons" wrote:

Hi all,

How to code:

If rownumber 1 and rownumber < 43 And an entire row is selected Then
....

The first part is no problem, but I don't know what to do with "And an
entire row is selected "

Your help will be appreciated.

Jack Sons
The Netherlands







  #6   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 380
Default VBA how to check if entire row is selected?

Sub JackSons()
Dim rownumber As Long

rownumber = ActiveCell.Row
If rownumber 1 And rownumber < 43 And _
Selection.Columns.Count = ActiveSheet.Columns.Count Then
'your code
End If

End Sub

--

HTH

Bob Phillips

(replace xxxx in the email address with gmail if mailing direct)

"Jack Sons" wrote in message
...
GS,

Thank you, but I don't want a message box to appear. Depending on wether

an
entire row is selected or only one cell or a limited group of cells, I

will
let something happen. I just need to know in that part of the code what in
the sheet is selected, an entire row or something else.

Jack.

"Gary''s Student" schreef in
bericht ...
first check that only one row is selected:

MsgBox (Selection.Rows.Count)

and then check that the entire row is selected:

MsgBox (Selection.Count)

for a complete single row, the first should be 1 and the second should

be
256
--
Gary's Student


"Jack Sons" wrote:

Hi all,

How to code:

If rownumber 1 and rownumber < 43 And an entire row is selected Then
....

The first part is no problem, but I don't know what to do with "And an
entire row is selected "

Your help will be appreciated.

Jack Sons
The Netherlands







  #7   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 144
Default VBA how to check if entire row is selected?

Bob and Dave,

Thank you very much, would never have found this code myself.

Jack.

"Jack Sons" schreef in bericht
...
Hi all,

How to code:

If rownumber 1 and rownumber < 43 And an entire row is selected Then
....

The first part is no problem, but I don't know what to do with "And an
entire row is selected "

Your help will be appreciated.

Jack Sons
The Netherlands



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
Linked Check Boxes blueegypt Excel Discussion (Misc queries) 4 May 12th 06 10:36 PM
Can Not Check more than 1 check box jamphan Excel Discussion (Misc queries) 1 May 5th 06 04:58 PM
... Can I set Spell Check to automatically check my spelling ... Dr. Darrell Setting up and Configuration of Excel 0 March 21st 06 09:26 PM
how to colour the entire row with the selected word murtuza kahn Excel Discussion (Misc queries) 1 March 15th 06 10:37 PM
Copy Selected cells down a row with macro DB33 Excel Discussion (Misc queries) 1 February 15th 06 06:33 PM


All times are GMT +1. The time now is 11:49 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"