Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Current Selected Range


Hi,

I'm sure this is so simple - but i cant get my head round it!

All i want is the macro to run on the current selected range (jus
format some cells) but i dont want any message boxes the user jus
highlights the range and then hits the macro key.

Sub FormatCells()

Dim myRange As Range
Set myRange = ActiveCell.Selection (tried ActiveSheet.Selection an
varoius others but to no avail!)

myRange.Interior.Color = vbBlue
'etc

End Sub

Wondered if anyone could provide some help

Thank

--
infojma
-----------------------------------------------------------------------
infojmac's Profile: http://www.excelforum.com/member.php...fo&userid=1078
View this thread: http://www.excelforum.com/showthread.php?threadid=56177

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 22,906
Default Current Selected Range

Either of these will do.

Sub formatcells()
Dim myRange As Range
Set myRange = Selection
myRange.Interior.Color = vbBlue
End Sub

Sub formatcells22()
With Selection
..Interior.Color = vbBlue
End With
End Sub


Gord Dibben MS Excel MVP

On Sat, 15 Jul 2006 17:11:08 -0400, infojmac
wrote:


Hi,

I'm sure this is so simple - but i cant get my head round it!

All i want is the macro to run on the current selected range (just
format some cells) but i dont want any message boxes the user just
highlights the range and then hits the macro key.

Sub FormatCells()

Dim myRange As Range
Set myRange = ActiveCell.Selection (tried ActiveSheet.Selection and
varoius others but to no avail!)

myRange.Interior.Color = vbBlue
'etc

End Sub

Wondered if anyone could provide some help

Thanks


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 695
Default Current Selected Range

try

Sub FormatCells()
Selection.Interior.ColorIndex = 5
End Sub



"infojmac" skrev:


Hi,

I'm sure this is so simple - but i cant get my head round it!

All i want is the macro to run on the current selected range (just
format some cells) but i dont want any message boxes the user just
highlights the range and then hits the macro key.

Sub FormatCells()

Dim myRange As Range
Set myRange = ActiveCell.Selection (tried ActiveSheet.Selection and
varoius others but to no avail!)

myRange.Interior.Color = vbBlue
'etc

End Sub

Wondered if anyone could provide some help

Thanks


--
infojmac
------------------------------------------------------------------------
infojmac's Profile: http://www.excelforum.com/member.php...o&userid=10787
View this thread: http://www.excelforum.com/showthread...hreadid=561776


  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,452
Default Current Selected Range

Sub test()

Dim rng As Range

Set rng = Selection

rng.Interior.ColorIndex = 3

End Sub

You can do it directly on Selection as well, without setting a range.

RBS

"infojmac" wrote in
message ...

Hi,

I'm sure this is so simple - but i cant get my head round it!

All i want is the macro to run on the current selected range (just
format some cells) but i dont want any message boxes the user just
highlights the range and then hits the macro key.

Sub FormatCells()

Dim myRange As Range
Set myRange = ActiveCell.Selection (tried ActiveSheet.Selection and
varoius others but to no avail!)

myRange.Interior.Color = vbBlue
'etc

End Sub

Wondered if anyone could provide some help

Thanks


--
infojmac
------------------------------------------------------------------------
infojmac's Profile:
http://www.excelforum.com/member.php...o&userid=10787
View this thread: http://www.excelforum.com/showthread...hreadid=561776


  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 22,906
Default Current Selected Range

Or simply

Sub formatcells()
Selection.Interior.Color = vbBlue
End Suib

Gord


On Sat, 15 Jul 2006 14:28:02 -0700, Gord Dibben <gorddibbATshawDOTca wrote:

Either of these will do.

Sub formatcells()
Dim myRange As Range
Set myRange = Selection
myRange.Sub formatcells22()
End Sub

Sub formatcells22()
With Selection
.Interior.Color = vbBlue
End With
End Sub


Gord Dibben MS Excel MVP

On Sat, 15 Jul 2006 17:11:08 -0400, infojmac
wrote:


Hi,

I'm sure this is so simple - but i cant get my head round it!

All i want is the macro to run on the current selected range (just
format some cells) but i dont want any message boxes the user just
highlights the range and then hits the macro key.

Sub FormatCells()

Dim myRange As Range
Set myRange = ActiveCell.Selection (tried ActiveSheet.Selection and
varoius others but to no avail!)

myRange.Interior.Color = vbBlue
'etc

End Sub

Wondered if anyone could provide some help

Thanks


Gord Dibben MS Excel MVP


  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Current Selected Range


All working now.

Thanks everyon

--
infojma
-----------------------------------------------------------------------
infojmac's Profile: http://www.excelforum.com/member.php...fo&userid=1078
View this thread: http://www.excelforum.com/showthread.php?threadid=56177

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
Macro to run relative to current selected cell MahD Excel Discussion (Misc queries) 3 December 11th 06 06:18 AM
a way to color the CURRENT row or cell when selected haneira Excel Programming 2 June 6th 05 10:23 AM
Code for current sheet selected... Brad Excel Programming 3 March 11th 05 04:29 PM
how can one obtain the current selected cell value Susan Hayes Excel Programming 3 December 14th 04 10:31 AM
plotting chart with user selected range from current workbook annette2002 Excel Programming 0 June 5th 04 03:16 AM


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