ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Discussion (Misc queries) (https://www.excelbanter.com/excel-discussion-misc-queries/)
-   -   referencing only rows with data (https://www.excelbanter.com/excel-discussion-misc-queries/235050-referencing-only-rows-data.html)

Rich S.

referencing only rows with data
 
i'm new to macros(cursor only), and i want it to create and print a graph for
each row of data(about 25 columns wide). If I select the first row, how can i
have the macro keep selecting until the last row of data? Thank you, Rich

joel

referencing only rows with data
 
First, it is not recommended using select. The macro recorder uses it but I
normally rewrite recorded macro not using the select. You need to select
chart which I consider a bug in VBA.


Here is recorded macro

Sub Macro1()
'
' Macro1 Macro
'

'
ActiveSheet.Shapes.AddChart.Select
ActiveChart.SetSourceData Source:=Range("'Sheet1'!$A$4:$N$4")
ActiveChart.ChartType = xlXYScatterSmooth
End Sub


Here is my modified macro

Sub AddCharts()

With ActiveSheet
RowCount = 1
Do While .Range("A" & RowCount) < ""
LastCol = .Cells(RowCount, Columns.Count).End(xlToLeft).Column
Set ChartRange = .Range(.Range("A" & RowCount), .Cells(RowCount, LastCol))

Set MyChart = .Shapes.AddChart
MyChart.Select
With ActiveChart

.SetSourceData Source:=ChartRange
.ChartType = xlXYScatterSmooth
End With
RowCount = RowCount + 1
Loop
End With
End Sub

:

i'm new to macros(cursor only), and i want it to create and print a graph for
each row of data(about 25 columns wide). If I select the first row, how can i
have the macro keep selecting until the last row of data? Thank you, Rich


Rich S.

referencing only rows with data
 
Thanks Joel. This may be a step or two ahead of my current macro ability but
gives me a chance to take it to the next level !!

"Joel" wrote:

First, it is not recommended using select. The macro recorder uses it but I
normally rewrite recorded macro not using the select. You need to select
chart which I consider a bug in VBA.


Here is recorded macro

Sub Macro1()
'
' Macro1 Macro
'

'
ActiveSheet.Shapes.AddChart.Select
ActiveChart.SetSourceData Source:=Range("'Sheet1'!$A$4:$N$4")
ActiveChart.ChartType = xlXYScatterSmooth
End Sub


Here is my modified macro

Sub AddCharts()

With ActiveSheet
RowCount = 1
Do While .Range("A" & RowCount) < ""
LastCol = .Cells(RowCount, Columns.Count).End(xlToLeft).Column
Set ChartRange = .Range(.Range("A" & RowCount), .Cells(RowCount, LastCol))

Set MyChart = .Shapes.AddChart
MyChart.Select
With ActiveChart

.SetSourceData Source:=ChartRange
.ChartType = xlXYScatterSmooth
End With
RowCount = RowCount + 1
Loop
End With
End Sub

:

i'm new to macros(cursor only), and i want it to create and print a graph for
each row of data(about 25 columns wide). If I select the first row, how can i
have the macro keep selecting until the last row of data? Thank you, Rich



All times are GMT +1. The time now is 02:39 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com