Hello
I have some code in the start of my macro that looks for the last row in column P and then selects all that column all the way upto row 17 which works fine. The next bit of code was generated by me recording a macro of inserting a line graph of the data previously selected at the start of the macro and naming the graph "subtwist" and scaling it a bit to suit the size of my screen.
It all works fine but the problem is that it does not quite work how I need it when I run it on a different file. On the original file there was 3677 lines of data which you can see from the section of code where it is making the graph. If I run this macro on a new sheet that for example only has 1500 lines of data it produces a graph from 3677 lines. How can I make the graph select the data range that the first bit of code identifies?
thanks
here is the code I have in the macro.
Sub RawLogProcessing()
'
' RawLogProcessing Macro
'
' Keyboard Shortcut: Ctrl+d
'
' Select Data from bottom of column P up and stop at P17
'
Dim lr As Long
Dim rngAllData As Range
lr = Worksheets("Sheet1").Cells(Rows.Count, "P").End(xlUp).Row
Set rngAllData = Worksheets("Sheet1").Range("P17:P" & lr)
rngAllData.Select
'insert the subtwist graph
ActiveSheet.Shapes.AddChart2(332, xlLineMarkers).Select
ActiveChart.SetSourceData Source:=Range("Sheet1!$P$17:$P$3677")
ActiveSheet.Shapes("Chart 1").ScaleWidth 1.85625, msoFalse, _
msoScaleFromBottomRight
ActiveSheet.Shapes("Chart 1").ScaleHeight 0.9670140712, msoFalse, _
msoScaleFromTopLeft
ActiveSheet.Shapes("Chart 1").ScaleWidth 1.430976431, msoFalse, _
msoScaleFromTopLeft
ActiveSheet.Shapes("Chart 1").ScaleHeight 1.0143626544, msoFalse, _
msoScaleFromTopLeft
ActiveChart.ChartTitle.Select
ActiveChart.ChartTitle.Text = "Subtwist"
Selection.Format.TextFrame2.TextRange.Characters.Text = "Subtwist"
With Selection.Format.TextFrame2.TextRange.Characters(1, 8).ParagraphFormat
.TextDirection = msoTextDirectionLeftToRight
.Alignment = msoAlignCenter
End With
With Selection.Format.TextFrame2.TextRange.Characters(1, 8).Font
.BaselineOffset = 0
.Bold = msoFalse
.NameComplexScript = "+mn-cs"
.NameFarEast = "+mn-ea"
.Fill.Visible = msoTrue
.Fill.ForeColor.RGB = RGB(89, 89, 89)
.Fill.Transparency = 0
.Fill.Solid
.Size = 14
.Italic = msoFalse
.Kerning = 12
.Name = "+mn-lt"
.UnderlineStyle = msoNoUnderline
.Spacing = 0
.Strike = msoNoStrike
End With
ActiveChart.ChartArea.Select
End Sub
Bookmarks