K
Karen
Hi all
I am using the macro below which I found in one of the threads to draw
data from a "Summary" sheet based on a helper column - "G" in
readiness for a chart.
I would like however to reuse this macro on any of the sheets within
my workbook and not just the "Summary" sheet. The other sheets also
have the same helper column etc.
How could I make the code Generic?.
I tried Activesheet.select but have a problem when returning to it
which I'd like to.
TIA
Karen
Sub CreateChart()
Application.DisplayAlerts = False
Sheets("Summary").Select
' Find the last row of data
FinalRow = Range("A65536").End(xlUp).Row
' Loop through each row
For x = 3 To FinalRow
' Decide if to copy based on entry column G
ThisValue = Range("G" & x).Value
If ThisValue = "1" Then
Range("A" & x & ":AG" & x).Copy
Sheets("Chart").Select
NextRow = Range("A65536").End(xlUp).Row + 1
Range("A" & NextRow).Select
'ActiveSheet.Paste
Selection.PasteSpecial Paste:=xlValues, Operation:=xlNone,
SkipBlanks:= _
False, Transpose:=False
Sheets("Summary").Select
End If
Next x
Cleanup
Chart
Sheets("Summary").Select
Application.DisplayAlerts = True
End Sub
I am using the macro below which I found in one of the threads to draw
data from a "Summary" sheet based on a helper column - "G" in
readiness for a chart.
I would like however to reuse this macro on any of the sheets within
my workbook and not just the "Summary" sheet. The other sheets also
have the same helper column etc.
How could I make the code Generic?.
I tried Activesheet.select but have a problem when returning to it
which I'd like to.
TIA
Karen
Sub CreateChart()
Application.DisplayAlerts = False
Sheets("Summary").Select
' Find the last row of data
FinalRow = Range("A65536").End(xlUp).Row
' Loop through each row
For x = 3 To FinalRow
' Decide if to copy based on entry column G
ThisValue = Range("G" & x).Value
If ThisValue = "1" Then
Range("A" & x & ":AG" & x).Copy
Sheets("Chart").Select
NextRow = Range("A65536").End(xlUp).Row + 1
Range("A" & NextRow).Select
'ActiveSheet.Paste
Selection.PasteSpecial Paste:=xlValues, Operation:=xlNone,
SkipBlanks:= _
False, Transpose:=False
Sheets("Summary").Select
End If
Next x
Cleanup
Chart
Sheets("Summary").Select
Application.DisplayAlerts = True
End Sub