Advertisement
Guest User

Untitled

a guest
Nov 22nd, 2014
129
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.85 KB | None | 0 0
  1. Dim i As Long
  2. Dim LastRow As Long
  3. Dim LastColumn As Long
  4. Dim cht As Chart
  5.  
  6. LastRow = Range("A65536").End(xlUp).row
  7. LastColumn = Range("A1").End(xlToRight).Column
  8.  
  9. For i = 2 To LastRow
  10. Dim location As String
  11.  
  12. Range("$A$i:$LastColumn").Select
  13. ActiveSheet.Shapes.AddChart.Select
  14. ActiveChart.ChartType = xlLine
  15. ActiveChart.SetSourceData Source:=Range("Sheet1!$A$i:$LastColumn")
  16.  
  17. With ActiveChart.Parent
  18. .Height = 225 ' resize
  19. .Width = 500 ' resize
  20.  
  21. ActiveChart.ChartArea.Copy
  22. Sheets("Sheet2").Select
  23. ActiveSheet.Pictures.Paste.Select
  24. Sheets("Sheet1").Select
  25. Application.Run ("DeleteEmbeddedCharts")
  26.  
  27. End With
  28. Next i
  29. End Sub
  30.  
  31. Sub main()
  32. 'variable declaration
  33. Dim i As Long
  34. Dim LastRow As Long
  35. Dim LastColumn As Long
  36. Dim chrt As Chart
  37.  
  38. 'Find the last used row
  39. LastRow = Sheets("Sheet1").Range("A65536").End(xlUp).Row
  40.  
  41. 'Find the last used column
  42. LastColumn = Sheets("Sheet1").Range("A1").End(xlToRight).Column
  43.  
  44. 'Looping from second row till last row which has the data
  45. For i = 2 To LastRow
  46. 'Sheet 2 is selected bcoz charts will be inserted here
  47. Sheets("Sheet2").Select
  48.  
  49. 'Adds chart to the sheet
  50. Set chrt = Sheets("Sheet2").Shapes.AddChart.Chart
  51. 'sets the chart type
  52. chrt.ChartType = xlLine
  53.  
  54. 'now the line chart is added...setting its data source here
  55. With Sheets("Sheet1")
  56. chrt.SetSourceData Source:=.Range(.Cells(i, 1), .Cells(i, LastColumn))
  57. End With
  58.  
  59. 'Left & top are used to adjust the position of chart on sheet
  60. chrt.ChartArea.Left = 1
  61. chrt.ChartArea.Top = (i - 2) * chrt.ChartArea.Height
  62.  
  63. Next
  64.  
  65. End Sub
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement