Home |
Search |
Today's Posts |
|
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Hi all,
Can someone let me know if its possible to write a macro that will allow me to change the range where it says in the worksheet Set Rng1 = Me.Range ("M2:M198") ? Sometimes I only need to see range between, say M2:M20 but I don't want to have to go into the code to chane it. The follow worksheet module is as follows: Private Sub Worksheet_Change(ByVal Target As Range) Dim n As Long Dim Rng1 As Range, Rng1A As Range, Rng1P As Range Dim Rng2 As Range, Rng3 As Range, Rng3A As Range Dim Rng4 As Range, Rng5 As Range, rCell As Range Set Rng1 = Me.Range("M2:M198") On Error Resume Next Set Rng1A = Intersect(Target, Rng1) Set Rng1P = Intersect(Target, Rng1.Precedents) On Error GoTo 0 If Rng1A Is Nothing And Rng1P Is Nothing Then Exit Sub If Not Rng1A Is Nothing Then If Not Rng1P Is Nothing Then Set Rng2 = Union(Rng1A, Rng1P) Else Set Rng2 = Rng1A End If Else Set Rng2 = Rng1P End If Set Rng3 = Intersect(Target, Rng2) On Error Resume Next Set Rng3A = Rng3.Dependents On Error GoTo 0 If Not Rng1A Is Nothing Then If Not Rng3A Is Nothing Then Set Rng4 = Union(Rng1A, Intersect(Rng1, Rng3A)) Else Set Rng4 = Rng1A End If Else Set Rng4 = Intersect(Rng1, Rng3A) End If For Each rCell In Rng4.Cells If Not IsError(rCell.Value) Then If rCell.Value 1 Then If Not Rng5 Is Nothing Then Set Rng5 = Union(Rng5, rCell) Else Set Rng5 = rCell End If End If End If Next If Rng5 Is Nothing Then Exit Sub With Rng5 For n = 1 To 5 With .Font If .ColorIndex = 2 Then .ColorIndex = 3 _ Else .ColorIndex = 2 End With With .Interior If .ColorIndex = 3 Then .ColorIndex = 2 _ Else .ColorIndex = 3 End With Application.Wait Now + TimeValue("00:00:01") Next .Font.ColorIndex = 3 .Interior.ColorIndex = 2 End With End Sub Sometimes I don't need to see all the cells flashing between M2:M198, so if there is a macro that can be written to allow to see a range between say, M2:M15 that would great. Cheers Carlton *** Sent via Developersdex http://www.developersdex.com *** |
#3
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
you could put a number in cell d1 and use that to modify. Or, use an input
box to ask for the number. Sub setrng() 'Set rng1 = Range("a2:a19") Set rng1 = Range("a2:a" & Range("d1")) rng1.Select End Sub -- Don Guillett SalesAid Software "Carlton Patterson" wrote in message ... Hi all, Can someone let me know if its possible to write a macro that will allow me to change the range where it says in the worksheet Set Rng1 = Me.Range ("M2:M198") ? Sometimes I only need to see range between, say M2:M20 but I don't want to have to go into the code to chane it. The follow worksheet module is as follows: Private Sub Worksheet_Change(ByVal Target As Range) Dim n As Long Dim Rng1 As Range, Rng1A As Range, Rng1P As Range Dim Rng2 As Range, Rng3 As Range, Rng3A As Range Dim Rng4 As Range, Rng5 As Range, rCell As Range Set Rng1 = Me.Range("M2:M198") On Error Resume Next Set Rng1A = Intersect(Target, Rng1) Set Rng1P = Intersect(Target, Rng1.Precedents) On Error GoTo 0 If Rng1A Is Nothing And Rng1P Is Nothing Then Exit Sub If Not Rng1A Is Nothing Then If Not Rng1P Is Nothing Then Set Rng2 = Union(Rng1A, Rng1P) Else Set Rng2 = Rng1A End If Else Set Rng2 = Rng1P End If Set Rng3 = Intersect(Target, Rng2) On Error Resume Next Set Rng3A = Rng3.Dependents On Error GoTo 0 If Not Rng1A Is Nothing Then If Not Rng3A Is Nothing Then Set Rng4 = Union(Rng1A, Intersect(Rng1, Rng3A)) Else Set Rng4 = Rng1A End If Else Set Rng4 = Intersect(Rng1, Rng3A) End If For Each rCell In Rng4.Cells If Not IsError(rCell.Value) Then If rCell.Value 1 Then If Not Rng5 Is Nothing Then Set Rng5 = Union(Rng5, rCell) Else Set Rng5 = rCell End If End If End If Next If Rng5 Is Nothing Then Exit Sub With Rng5 For n = 1 To 5 With .Font If .ColorIndex = 2 Then .ColorIndex = 3 _ Else .ColorIndex = 2 End With With .Interior If .ColorIndex = 3 Then .ColorIndex = 2 _ Else .ColorIndex = 3 End With Application.Wait Now + TimeValue("00:00:01") Next .Font.ColorIndex = 3 .Interior.ColorIndex = 2 End With End Sub Sometimes I don't need to see all the cells flashing between M2:M198, so if there is a macro that can be written to allow to see a range between say, M2:M15 that would great. Cheers Carlton *** Sent via Developersdex http://www.developersdex.com *** |
#4
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Hello Don,
I quite like your suggestion. I was just wondering if it could be a little more selective? For example, is there a way that I could input in d1 a range of cells instead of just adding a number? Cheers Carlton *** Sent via Developersdex http://www.developersdex.com *** |
#5
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
one simple way
Set rng1 = Range("" & Range("d1") & "") -- Don Guillett SalesAid Software "Carlton Patterson" wrote in message ... Hello Don, I quite like your suggestion. I was just wondering if it could be a little more selective? For example, is there a way that I could input in d1 a range of cells instead of just adding a number? Cheers Carlton *** Sent via Developersdex http://www.developersdex.com *** |
#6
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Hi Carlton,
Try using a named range. Then you can simply redefine your desired flash range without touching the code. So change: Set Rng1 = Me.Range ("M2:M198") ? to Set Rng1 = Me.Range ("MyRange") --- Regards, Norman "Carlton Patterson" wrote in message ... Hi all, Can someone let me know if its possible to write a macro that will allow me to change the range where it says in the worksheet Set Rng1 = Me.Range ("M2:M198") ? Sometimes I only need to see range between, say M2:M20 but I don't want to have to go into the code to chane it. The follow worksheet module is as follows: Private Sub Worksheet_Change(ByVal Target As Range) Dim n As Long Dim Rng1 As Range, Rng1A As Range, Rng1P As Range Dim Rng2 As Range, Rng3 As Range, Rng3A As Range Dim Rng4 As Range, Rng5 As Range, rCell As Range Set Rng1 = Me.Range("M2:M198") On Error Resume Next Set Rng1A = Intersect(Target, Rng1) Set Rng1P = Intersect(Target, Rng1.Precedents) On Error GoTo 0 If Rng1A Is Nothing And Rng1P Is Nothing Then Exit Sub If Not Rng1A Is Nothing Then If Not Rng1P Is Nothing Then Set Rng2 = Union(Rng1A, Rng1P) Else Set Rng2 = Rng1A End If Else Set Rng2 = Rng1P End If Set Rng3 = Intersect(Target, Rng2) On Error Resume Next Set Rng3A = Rng3.Dependents On Error GoTo 0 If Not Rng1A Is Nothing Then If Not Rng3A Is Nothing Then Set Rng4 = Union(Rng1A, Intersect(Rng1, Rng3A)) Else Set Rng4 = Rng1A End If Else Set Rng4 = Intersect(Rng1, Rng3A) End If For Each rCell In Rng4.Cells If Not IsError(rCell.Value) Then If rCell.Value 1 Then If Not Rng5 Is Nothing Then Set Rng5 = Union(Rng5, rCell) Else Set Rng5 = rCell End If End If End If Next If Rng5 Is Nothing Then Exit Sub With Rng5 For n = 1 To 5 With .Font If .ColorIndex = 2 Then .ColorIndex = 3 _ Else .ColorIndex = 2 End With With .Interior If .ColorIndex = 3 Then .ColorIndex = 2 _ Else .ColorIndex = 3 End With Application.Wait Now + TimeValue("00:00:01") Next .Font.ColorIndex = 3 .Interior.ColorIndex = 2 End With End Sub Sometimes I don't need to see all the cells flashing between M2:M198, so if there is a macro that can be written to allow to see a range between say, M2:M15 that would great. Cheers Carlton *** Sent via Developersdex http://www.developersdex.com *** |
#7
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Hi Norman,
I'm going work on Don's suggestion, in the meantime could you explain what you mean when you mentioned, 'Then you can simply redefine your desired flash range without touching the code'? Cheers Carlton *** Sent via Developersdex http://www.developersdex.com *** |
#8
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Hi Norman,
I made the changes as suggested but I a run-time error 1004: Method 'Range' of object'_Worksheet' failed. Carlton *** Sent via Developersdex http://www.developersdex.com *** |
#9
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Hi Carlton,
Did you define the named range in the worksheet? If not, wiyh the desired range selected - say M2:M20 - type MyRangw in the Name box and hit Enter to confirm thr name. With the name defined, the code worked for me. --- Regards, Norman "Carlton Patterson" wrote in message ... Hi Norman, I made the changes as suggested but I a run-time error 1004: Method 'Range' of object'_Worksheet' failed. Carlton *** Sent via Developersdex http://www.developersdex.com *** |
#10
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Hi Norman,
To be honest I'm not quite sure how to define a named range. Can you show me? Cheers Carlton *** Sent via Developersdex http://www.developersdex.com *** |
#11
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Hi Carlton,
Assume that you have adapted the code to use the named rangeMyRange which refers to M2:M198, this will be your flash range, Changing the MyRange definition (via Insert ! Name | Define) to refer to M2:M20, only cells in this latter range will be flashable. In practice, given that you might wish frequently to limit (or extend) the range of information to be monitored, it would be convenient to add a toolbar (or sheet) button to automate range selection .. --- Regards, Norman "Carlton Patterson" wrote in message ... Hi Norman, I'm going work on Don's suggestion, in the meantime could you explain what you mean when you mentioned, 'Then you can simply redefine your desired flash range without touching the code'? Cheers Carlton *** Sent via Developersdex http://www.developersdex.com *** |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
Change chart range with macro | Charts and Charting in Excel | |||
How can change range to select active rows instead of :=Range("S10 | Excel Discussion (Misc queries) | |||
Macro to change Chart Range when inserting a column | Charts and Charting in Excel | |||
Why does macro change print range? | Excel Programming | |||
Macro to change list box input range based on selection made in another cell | Excel Programming |