Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.misc
 
Posts: n/a
Default What is Range For Chart AutoFilter Range VBA?

Below Is a snippet of code for a VBA Macro to plot an xyScatter chart on any
selected two columns of a spreadsheet. I've modified the code but the original
comes from Jon Peltiers' excellent site

When I use the sutofilter on the spreadsheet, this code will not plot the
autofiltered columns correctly.

How do I set the intersect range(rng) so that only the autofiltered visible will
plot?

Thanks for any help.

=======xyScatter Plot VBA below=============
Sub myScatterChart()

'On Error Resume Next
Application.ScreenUpdating = False
Application.Calculation = xlCalculationManual
Dim curwk As Worksheet
Dim myCell As Range
Dim rng As Range
Dim myName As String, sColLabel1 As String, sColLabel2 As String
Dim ChartName As String
Dim ii As Long
Dim lNumRows As Long
Dim lNumCols As Long
Dim x As Long

'x = ActiveSheet.UsedRange.Rows.Count
ii = 0
myName = ""

Set rng = Intersect(ActiveSheet.UsedRange, Selection)

Select Case rng.Areas.Count
Case Is = 1
sColLabel2 = rng.Areas(1).Cells(1, 1)
sColLabel1 = "Number"
Case Is = 2
sColLabel1 = rng.Areas(1).Cells(1, 1)
sColLabel2 = rng.Areas(2).Cells(1, 1)
If rng.Areas(2).Column < rng.Areas(1).Column Then
sColLabel1 = rng.Areas(2).Cells(1, 1)
sColLabel2 = rng.Areas(1).Cells(1, 1)
End If
End Select

myName = sColLabel1 & sColLabel2

Charts.Add

ChartName = ActiveChart.Name

If myName < "" And Not myNameExists(myName) Then ActiveChart.Name = myName

With ActiveChart
.ChartType = xlXYScatter
.SetSourceData Source:=rng, PlotBy:=xlColumns
.Location Whe=xlLocationAsNewSheet
.Move After:=Sheets(Sheets.Count)
.HasTitle = True
.ChartTitle.Characters.Text = sColLabel1 & " vs " & sColLabel2
.Axes(xlCategory, xlPrimary).HasTitle = True
.Axes(xlCategory, xlPrimary).AxisTitle.Characters.Text = sColLabel1
.Axes(xlValue, xlPrimary).HasTitle = True
.Axes(xlValue, xlPrimary).AxisTitle.Characters.Text = sColLabel2
.PlotArea.Select
With Selection.Border
.ColorIndex = 16
.Weight = xlThin
.LineStyle = xlContinuous
End With
With Selection.Interior
.ColorIndex = 2
.PatternColorIndex = 1
.Pattern = xlSolid
End With
With .Axes(xlCategory)
.HasMajorGridlines = True
.HasMinorGridlines = False
End With
With .Axes(xlValue)
.HasMajorGridlines = True
.HasMinorGridlines = False
End With

.SeriesCollection(1).Trendlines.Add(Type:=xlLinear , Forward _
:=0, Backward:=0, DisplayEquation:=True, DisplayRSquared:=True).Select
.PlotArea.Select
End With

Application.Calculation = xlCalculationAutomatic
Application.ScreenUpdating = True

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
Help with using range names in sum function soteman2005 Excel Worksheet Functions 2 November 28th 05 04:43 PM
Array to named range conversion... i-Zapp Excel Discussion (Misc queries) 4 October 25th 05 09:09 PM
How to Select a relative range with Using "Find" and Offset() Dennis Excel Discussion (Misc queries) 7 July 27th 05 03:57 PM
Cannot Expand Named Range - when size of the Range exceeds Snig Excel Discussion (Misc queries) 1 July 7th 05 01:46 PM
Counting empty cells within a range of cells Rosehill - ExcelForums.com New Users to Excel 2 May 2nd 05 08:53 AM


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