Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4
Default VBA limit from sheet to several ranges

VBA: Looking for a way to limit the range on this from the whole sheet
to several non-contigous ranges without slowing it way down. Any
suggestions would be greatly appreciated.


Private Sub Worksheet_Change(ByVal Target As Range)

Dim Cell As Range

Dim Rng1 As Range

On Error Resume Next

Set Rng1 = ActiveSheet.Cells.SpecialCells(xlCellTypeFormulas, 1)

On Error GoTo 0

If Rng1 Is Nothing Then

Set Rng1 = Range(Target.Address)

Else

Set Rng1 = Union(Range(Target.Address), Rng1)

End If

For Each Cell In Rng1

Select Case Cell.Value

Case vbNullString

Cell.Interior.ColorIndex = xlNone

Cell.Font.Bold = False

Case "1TR", "1PR", "1S1", "1S2"

Cell.Interior.ColorIndex = 37

Cell.Font.Bold = True

Cell.Font.ColorIndex = 1

Case "TR", "PR", "S1", "S2"
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,533
Default VBA limit from sheet to several ranges

Hi

Look at the code below:

Private Sub Worksheet_Change(ByVal Target As Range)
Dim TestRange As Range
Set TestRange = Union(Range("A1:B3"), Range("D10:H45"))

Set isect = Intersect(Target, TestRange)
If Not isect Is Nothing Then
MsgBox ("Intersection")
' Code to manipulate target

End If

End Sub

Regards,
Per

skrev i meddelelsen
...
VBA: Looking for a way to limit the range on this from the whole sheet
to several non-contigous ranges without slowing it way down. Any
suggestions would be greatly appreciated.


Private Sub Worksheet_Change(ByVal Target As Range)

Dim Cell As Range

Dim Rng1 As Range

On Error Resume Next

Set Rng1 = ActiveSheet.Cells.SpecialCells(xlCellTypeFormulas, 1)

On Error GoTo 0

If Rng1 Is Nothing Then

Set Rng1 = Range(Target.Address)

Else

Set Rng1 = Union(Range(Target.Address), Rng1)

End If

For Each Cell In Rng1

Select Case Cell.Value

Case vbNullString

Cell.Interior.ColorIndex = xlNone

Cell.Font.Bold = False

Case "1TR", "1PR", "1S1", "1S2"

Cell.Interior.ColorIndex = 37

Cell.Font.Bold = True

Cell.Font.ColorIndex = 1

Case "TR", "PR", "S1", "S2"


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 533
Default VBA limit from sheet to several ranges

Set Rng1 = Range(Target.Address)

Target IS a range. So if you need to use Rng1 all you need is this:

Set Rng1 = Target

That aside if you want the format of a formula cell to change when its value
changes, as it looks you do, why not use Conditional Formatting?

--
Jim
wrote in message
...
VBA: Looking for a way to limit the range on this from the whole sheet
to several non-contigous ranges without slowing it way down. Any
suggestions would be greatly appreciated.


Private Sub Worksheet_Change(ByVal Target As Range)

Dim Cell As Range

Dim Rng1 As Range

On Error Resume Next

Set Rng1 = ActiveSheet.Cells.SpecialCells(xlCellTypeFormulas, 1)

On Error GoTo 0

If Rng1 Is Nothing Then

Set Rng1 = Range(Target.Address)

Else

Set Rng1 = Union(Range(Target.Address), Rng1)

End If

For Each Cell In Rng1

Select Case Cell.Value

Case vbNullString

Cell.Interior.ColorIndex = xlNone

Cell.Font.Bold = False

Case "1TR", "1PR", "1S1", "1S2"

Cell.Interior.ColorIndex = 37

Cell.Font.Bold = True

Cell.Font.ColorIndex = 1

Case "TR", "PR", "S1", "S2"



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
Sheet copy limit LiAD Excel Discussion (Misc queries) 0 November 6th 09 07:43 AM
Limit to number of named ranges before Excel starts messing things up? S Davis Excel Worksheet Functions 3 September 12th 06 08:07 PM
Help! Limit on number of Ranges you can use at one time? Sandy Excel Programming 3 August 31st 05 08:03 AM
Copy Sheet Limit pumpbhoy Excel Programming 4 February 11th 05 05:29 PM
set time limit before closing sheet Maria Johansson Excel Programming 2 October 14th 03 08:00 AM


All times are GMT +1. The time now is 09:34 PM.

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"