Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.misc
DCSwearingen
 
Posts: n/a
Default Identifying a Selected Range in a Macro


When a user clicks and drags to highlight a range, how do I identify
that range in a macro?

Say the user highlights cells E6:G17, I want to give them the ability
to click a button that will do several things to that range.

I have tested my macro, but only when I have used a known range.


--
DCSwearingen


------------------------------------------------------------------------
DCSwearingen's Profile: http://www.excelforum.com/member.php...o&userid=21506
View this thread: http://www.excelforum.com/showthread...hreadid=535965

  #2   Report Post  
Posted to microsoft.public.excel.misc
Bob Phillips
 
Posts: n/a
Default Identifying a Selected Range in a Macro

That is Selection, as in

Msgbox Selection.Address

--
HTH

Bob Phillips

(remove nothere from email address if mailing direct)

"DCSwearingen"
wrote in message
news:DCSwearingen.26trd2_1145976316.3013@excelforu m-nospam.com...

When a user clicks and drags to highlight a range, how do I identify
that range in a macro?

Say the user highlights cells E6:G17, I want to give them the ability
to click a button that will do several things to that range.

I have tested my macro, but only when I have used a known range.


--
DCSwearingen


------------------------------------------------------------------------
DCSwearingen's Profile:

http://www.excelforum.com/member.php...o&userid=21506
View this thread: http://www.excelforum.com/showthread...hreadid=535965



  #3   Report Post  
Posted to microsoft.public.excel.misc
Bondi
 
Posts: n/a
Default Identifying a Selected Range in a Macro

Hi,

Here is a example of the With Selection:

Private Sub CommandButton1_Click()
With Selection
.Value = 1
End With
End Sub

Regards,
Bondi

  #4   Report Post  
Posted to microsoft.public.excel.misc
Dave Peterson
 
Posts: n/a
Default Identifying a Selected Range in a Macro

You can use Selection to get the user's current selection.

Dim myCell as range
for each mycell in selection.cells
...
next mycell

In fact, you could toss up an inputbox that allows the user to select the range.

Dim myRng as range
set myrng =nothing
on error resume next
set myrng = application.inputbox(Prompt:="Select a range!", type:=8)
on error goto 0

if myrng is nothing then
'user hit cancel
else
msgbox myrng.address
end if



DCSwearingen wrote:

When a user clicks and drags to highlight a range, how do I identify
that range in a macro?

Say the user highlights cells E6:G17, I want to give them the ability
to click a button that will do several things to that range.

I have tested my macro, but only when I have used a known range.

--
DCSwearingen

------------------------------------------------------------------------
DCSwearingen's Profile: http://www.excelforum.com/member.php...o&userid=21506
View this thread: http://www.excelforum.com/showthread...hreadid=535965


--

Dave Peterson
  #5   Report Post  
Posted to microsoft.public.excel.misc
DCSwearingen
 
Posts: n/a
Default Identifying a Selected Range in a Macro


Thank You for Responding!

I have been searching the help file all morning for this!


--
DCSwearingen


------------------------------------------------------------------------
DCSwearingen's Profile: http://www.excelforum.com/member.php...o&userid=21506
View this thread: http://www.excelforum.com/showthread...hreadid=535965

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
format macro Jonathan Cooper Excel Discussion (Misc queries) 5 January 9th 06 09:49 PM
checking that cells have a value before the workbook will close kcdonaldson Excel Worksheet Functions 8 December 5th 05 05:57 PM
Closing File Error jcliquidtension Excel Discussion (Misc queries) 4 October 20th 05 01:22 PM
Name a Range - Macro Danny Excel Worksheet Functions 0 October 14th 05 06:24 AM
Match function...random search? Les Excel Worksheet Functions 10 July 28th 05 12:54 PM


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

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

About Us

"It's about Microsoft Excel"