Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5
Default Help with setting range limits

Hi All,

I have put together the following sub which changes the color of whatever
cell is active to green.

Private Sub Workbook_SheetSelectionChange(ByVal Sh As Object, ByVal Target
As Excel.Range)
Static DataField As Range
If Not DataField Is Nothing Then
DataField.Interior.ColorIndex = xlColorIndexNone
End If
Target.Interior.ColorIndex = 4
Set DataField = Target

End Sub


My problem is that I have been unable to limit this routine to a specific
range of cells (actually two specific ranges) in this case D7:D14 and F7:F14

As it is right now, no matter what cell I click on, it turns green.

Any help would be much appreciated.

Pete


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Help with setting range limits

Private Sub Workbook_SheetSelectionChange(ByVal Sh As Object, ByVal Target
As Excel.Range)
if intersect(target,Range("D7:D14,F7:F14")) is Nothing then exit sub
Target.Interior.ColorIndex = 4
End Sub

Not sure what role DateField is playing.

--
Regards,
Tom Ogilvy


"Pete Csiszar" wrote in message
news:05IDb.724346$6C4.299664@pd7tw1no...
Hi All,

I have put together the following sub which changes the color of whatever
cell is active to green.

Private Sub Workbook_SheetSelectionChange(ByVal Sh As Object, ByVal Target
As Excel.Range)
Static DataField As Range
If Not DataField Is Nothing Then
DataField.Interior.ColorIndex = xlColorIndexNone
End If
Target.Interior.ColorIndex = 4
Set DataField = Target

End Sub


My problem is that I have been unable to limit this routine to a specific
range of cells (actually two specific ranges) in this case D7:D14 and

F7:F14

As it is right now, no matter what cell I click on, it turns green.

Any help would be much appreciated.

Pete




  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 24
Default Help with setting range limits

Assuming that you want to set only the Range("D7:D14") and
the Range("F7:F14") to green and that you want to only set
those ranges to green by way of VBA(not by clicking). Try
this:

Private Sub Change_To_Green()

Range("D7:D14").Interior.ColorIndex = 4
Range("F7:F14").Interior.ColorIndex = 4

End Sub

Do you have further needs for this sub?

-IA


-----Original Message-----
Hi All,

I have put together the following sub which changes the

color of whatever
cell is active to green.

Private Sub Workbook_SheetSelectionChange(ByVal Sh As

Object, ByVal Target
As Excel.Range)
Static DataField As Range
If Not DataField Is Nothing Then
DataField.Interior.ColorIndex = xlColorIndexNone
End If
Target.Interior.ColorIndex = 4
Set DataField = Target

End Sub


My problem is that I have been unable to limit this

routine to a specific
range of cells (actually two specific ranges) in this

case D7:D14 and F7:F14

As it is right now, no matter what cell I click on, it

turns green.

Any help would be much appreciated.

Pete


.

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 102
Default Help with setting range limits

Have you considered using conditional formatting?
Warning this may not work very well on a work sheet that has to many
formulas.

Select Range to be affected by formatting (in this case) "D7:D14"
Select - Menu/Formatting/Conditional Formatting
Select - Formula is (from the drop down menu in top right of dialogue box)
Type - =CELL("Row") = $D7
Press Format button and then the "Patterns" tab - to choose a cell color to
apply when formula above is true

Right click on sheet name tab and select "View Code" and paste in the
following code:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
ActiveSheet.Calculate
End Sub

In order for the active worksheet to recalculate there must be at least one
formula in each row of the formatted range (in this case the formulas could
even be in range IV7:IV14 and the formatting should still work)

I'm using Excel 2002
--
Regards,
Rocky McKinley


"Pete Csiszar" wrote in message
news:05IDb.724346$6C4.299664@pd7tw1no...
Hi All,

I have put together the following sub which changes the color of whatever
cell is active to green.

Private Sub Workbook_SheetSelectionChange(ByVal Sh As Object, ByVal Target
As Excel.Range)
Static DataField As Range
If Not DataField Is Nothing Then
DataField.Interior.ColorIndex = xlColorIndexNone
End If
Target.Interior.ColorIndex = 4
Set DataField = Target

End Sub


My problem is that I have been unable to limit this routine to a specific
range of cells (actually two specific ranges) in this case D7:D14 and

F7:F14

As it is right now, no matter what cell I click on, it turns green.

Any help would be much appreciated.

Pete




  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5
Default Help with setting range limits


Tom,

Thanks!
DataField is just what I was what I wanted to call the highlighted cell.

What you've given me is the way to highlight all of the cells within the
range but my problem is that when I move to the next cell, the previous
cell remains green.
The point of my little sub was to just to have the currently active cell
be green and return to none upon moving to the next cell within my
specific ranges.

Does this make any sense?
TIA
Pete Csiszar P.Eng.



*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!


  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5
Default Help with setting range limits

Thanks Izar,

But not quite.
I would like the active cell to be green when I click on it. When I leave
the cell and click or down arrow etc. the next active cell becomes green and
the cell just left behind returns to xlColorIndexNone.

Sorry for being vague.

Regards,
Pete

"Izar Arcturus" wrote in message
...
Assuming that you want to set only the Range("D7:D14") and
the Range("F7:F14") to green and that you want to only set
those ranges to green by way of VBA(not by clicking). Try
this:

Private Sub Change_To_Green()

Range("D7:D14").Interior.ColorIndex = 4
Range("F7:F14").Interior.ColorIndex = 4

End Sub

Do you have further needs for this sub?

-IA


-----Original Message-----
Hi All,

I have put together the following sub which changes the

color of whatever
cell is active to green.

Private Sub Workbook_SheetSelectionChange(ByVal Sh As

Object, ByVal Target
As Excel.Range)
Static DataField As Range
If Not DataField Is Nothing Then
DataField.Interior.ColorIndex = xlColorIndexNone
End If
Target.Interior.ColorIndex = 4
Set DataField = Target

End Sub


My problem is that I have been unable to limit this

routine to a specific
range of cells (actually two specific ranges) in this

case D7:D14 and F7:F14

As it is right now, no matter what cell I click on, it

turns green.

Any help would be much appreciated.

Pete


.



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
y-axis auto range based on data limits hlmrspd Charts and Charting in Excel 5 May 24th 07 11:08 PM
Excel Addin:Setting the range to the Excel.Range object range prop Rp007 Excel Worksheet Functions 5 November 24th 06 04:30 PM
VBA setting Range Jeff Excel Discussion (Misc queries) 1 December 2nd 05 07:36 PM
range setting Mike Harris Excel Programming 5 November 22nd 03 05:07 AM
Setting a range using VBA [email protected] Excel Programming 4 November 14th 03 05:16 AM


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