Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.charting
external usenet poster
 
Posts: 354
Default VB pre-defined range ?


Hi all

I want to improve my VB colorbar sub programing to color bar chart below.
This sub has the problem of range pre-defined at A2:A9.
For Each Rng In Range("A2:A9") !!
How can I modify it so it can scan any range? Because my workbook change
often but the column name not change.
Thanks
Daniel


-------------------------------------------------------

Sub colorbarr()



Application.ScreenUpdating = False

Dim Rng As Range
Dim Cnt As Integer

Cnt = 1

For Each Rng In Range("A2:A9")
Set Pts = ActiveChart.SeriesCollection(1).Points(Cnt)
If Rng.Value = "im" Then
Pts.Interior.ColorIndex = 24
ElseIf Rng.Value = "surg" Then
Pts.Interior.ColorIndex = 45
ElseIf Rng.Value = "ms" Then
Pts.Interior.ColorIndex = 19
ElseIf Rng.Value = "other" Then
Pts.Interior.ColorIndex = 35
End If
Cnt = Cnt + 1
Next Rng
End Sub


  #2   Report Post  
Posted to microsoft.public.excel.charting
external usenet poster
 
Posts: 6,582
Default VB pre-defined range ?

Something like this:

Sub ColorBarr()

Dim rCell As Range
Dim rTotal As Range
Dim Cnt As Integer

If TypeName(Selection) < "Range" Then Exit Sub

Set rTotal = Selection

Cnt = 1

For Each rCell In rTotal.Cells
' etc.

- Jon
-------
Jon Peltier, Microsoft Excel MVP
Tutorials and Custom Solutions
Peltier Technical Services, Inc. - http://PeltierTech.com
_______


"Daniel" wrote in message
...

Hi all

I want to improve my VB colorbar sub programing to color bar chart below.
This sub has the problem of range pre-defined at A2:A9.
For Each Rng In Range("A2:A9") !!
How can I modify it so it can scan any range? Because my workbook change
often but the column name not change.
Thanks
Daniel


-------------------------------------------------------

Sub colorbarr()



Application.ScreenUpdating = False

Dim Rng As Range
Dim Cnt As Integer

Cnt = 1

For Each Rng In Range("A2:A9")
Set Pts = ActiveChart.SeriesCollection(1).Points(Cnt)
If Rng.Value = "im" Then
Pts.Interior.ColorIndex = 24
ElseIf Rng.Value = "surg" Then
Pts.Interior.ColorIndex = 45
ElseIf Rng.Value = "ms" Then
Pts.Interior.ColorIndex = 19
ElseIf Rng.Value = "other" Then
Pts.Interior.ColorIndex = 35
End If
Cnt = Cnt + 1
Next Rng
End Sub




  #3   Report Post  
Posted to microsoft.public.excel.charting
external usenet poster
 
Posts: 354
Default VB pre-defined range ?

Thanks Jon for respond my question
I modified my sub colorbar to scan all cells in column A and F. I tried
this as below to read the range in column A and F but it show error after
execute this macro ?

For Each Rng In Range ("A:A, F:F")

DO not know why and how should I change?
Daniel



"Jon Peltier" wrote:

Something like this:

Sub ColorBarr()

Dim rCell As Range
Dim rTotal As Range
Dim Cnt As Integer

If TypeName(Selection) < "Range" Then Exit Sub

Set rTotal = Selection

Cnt = 1

For Each rCell In rTotal.Cells
' etc.

- Jon
-------
Jon Peltier, Microsoft Excel MVP
Tutorials and Custom Solutions
Peltier Technical Services, Inc. - http://PeltierTech.com
_______


"Daniel" wrote in message
...

Hi all

I want to improve my VB colorbar sub programing to color bar chart below.
This sub has the problem of range pre-defined at A2:A9.
For Each Rng In Range("A2:A9") !!
How can I modify it so it can scan any range? Because my workbook change
often but the column name not change.
Thanks
Daniel


-------------------------------------------------------

Sub colorbarr()



Application.ScreenUpdating = False

Dim Rng As Range
Dim Cnt As Integer

Cnt = 1

For Each Rng In Range("A2:A9")
Set Pts = ActiveChart.SeriesCollection(1).Points(Cnt)
If Rng.Value = "im" Then
Pts.Interior.ColorIndex = 24
ElseIf Rng.Value = "surg" Then
Pts.Interior.ColorIndex = 45
ElseIf Rng.Value = "ms" Then
Pts.Interior.ColorIndex = 19
ElseIf Rng.Value = "other" Then
Pts.Interior.ColorIndex = 35
End If
Cnt = Cnt + 1
Next Rng
End Sub





  #4   Report Post  
Posted to microsoft.public.excel.charting
external usenet poster
 
Posts: 6,582
Default VB pre-defined range ?

Try

For Each Rng In Range("A:A, F:F").Cells

Then if you are doing the cells in each row of the two columns in
conjunction:

Dim Rng2 As Range
For Each Rng In Range("A:A").Cells
Set Rng2 = Rng.Offset(0, 5)

This way you can get both values and process them in the same algorithm.

Now, Range("A:A") has a lot of cells, so you could also try this:

Dim BigRange As Range
Dim Rng1 As Range
Dim Rng2 As Range

Set BigRange = Intersect(ActiveSheet.UsedRange,
ActiveSheet.Range("A:A"))

For Each Rng1 In BigRange.Cells
Set Rng2 = Rng1.Offset(0, 5)

- Jon
-------
Jon Peltier, Microsoft Excel MVP
Tutorials and Custom Solutions
Peltier Technical Services, Inc. - http://PeltierTech.com
_______


"Daniel" wrote in message
...
Thanks Jon for respond my question
I modified my sub colorbar to scan all cells in column A and F. I tried
this as below to read the range in column A and F but it show error after
execute this macro ?

For Each Rng In Range ("A:A, F:F")

DO not know why and how should I change?
Daniel



"Jon Peltier" wrote:

Something like this:

Sub ColorBarr()

Dim rCell As Range
Dim rTotal As Range
Dim Cnt As Integer

If TypeName(Selection) < "Range" Then Exit Sub

Set rTotal = Selection

Cnt = 1

For Each rCell In rTotal.Cells
' etc.

- Jon
-------
Jon Peltier, Microsoft Excel MVP
Tutorials and Custom Solutions
Peltier Technical Services, Inc. - http://PeltierTech.com
_______


"Daniel" wrote in message
...

Hi all

I want to improve my VB colorbar sub programing to color bar chart
below.
This sub has the problem of range pre-defined at A2:A9.
For Each Rng In Range("A2:A9") !!
How can I modify it so it can scan any range? Because my workbook
change
often but the column name not change.
Thanks
Daniel


-------------------------------------------------------

Sub colorbarr()



Application.ScreenUpdating = False

Dim Rng As Range
Dim Cnt As Integer

Cnt = 1

For Each Rng In Range("A2:A9")
Set Pts = ActiveChart.SeriesCollection(1).Points(Cnt)
If Rng.Value = "im" Then
Pts.Interior.ColorIndex = 24
ElseIf Rng.Value = "surg" Then
Pts.Interior.ColorIndex = 45
ElseIf Rng.Value = "ms" Then
Pts.Interior.ColorIndex = 19
ElseIf Rng.Value = "other" Then
Pts.Interior.ColorIndex = 35
End If
Cnt = Cnt + 1
Next Rng
End Sub







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
Name defined Range - Copy? John Buckley Excel Discussion (Misc queries) 1 August 1st 06 02:36 AM
How can I see defined name range? smart.daisy Excel Discussion (Misc queries) 2 March 6th 06 03:52 PM
Referencing defined range spartanmba Excel Discussion (Misc queries) 2 September 14th 05 01:28 AM
Defined range using more than one column Pat Excel Discussion (Misc queries) 5 January 18th 05 02:33 PM
Defined range problem Pat Excel Discussion (Misc queries) 8 January 17th 05 11:25 AM


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