taykaisheng
New Member
- Joined
- Jul 30, 2013
- Messages
- 10
Hello, I'm working on a program recently to automatic generate graph based on a set of data. However, I am facing some issues now as I need to select Column A and Column C to setSourceData for my graph as shown below
View image: table 1
I'm using CurrentRegion property to select the a table of data for chart creation
This is my progress so far..
Please advice as I'm new in VBA
View image: table 1
I'm using CurrentRegion property to select the a table of data for chart creation
This is my progress so far..
Code:
Public Function FourthTable()
Dim Source As Workbook
Dim Search As Range
Dim CR As Range
Dim CR2 As Range
Dim CR3 As Range
Dim CR4 As Range
SRT = "Service Request Tickets (IIT)"
Set Source = Workbooks.Open("C:\Users\HP\Desktop\test.xlsx")
Source.Worksheets("Sheet1").Activate
Set Search = ActiveSheet.Cells.Find(SRT)
With Source.Worksheets("Sheet1").Range(Search.Address).Offset(2, 0).Select
ActiveCell.CurrentRegion.Select
End With
Set CR = ActiveCell.CurrentRegion
CR.Resize(CR.Rows.Count - 1, CR.Columns.Count).Select
With Source.Worksheets("Sheet1").Range(Search.Address).Offset(2, 0).CurrentRegion
Set CR2 = .Resize(.Rows.Count - 1)
End With
With Source.Worksheets("Sheet1").Range(Search.Address).Offset(2, 0).CurrentRegion
Set CR3 = .Columns(3).Address
End With
With Source.Worksheets("Sheet1").Range(Search.Address).Offset(2, 0).CurrentRegion
Set CR4 = .Columns(1).Address
End With
ActiveSheet.Shapes.AddChart.Select
ActiveChart.SetSourceData Source:=ActiveWorkbook.Sheets(1).Range(CR3 & CR4)
ActiveChart.ChartType = xl3DBarClustered
With ActiveChart
.Perspective = 0
.Elevation = 15
.Rotation = 20
.RightAngleAxes = True
End With
ActiveSheet.ChartObjects(1).Activate
ActiveSheet.ChartObjects(1).Cut
With Sheets("Sheet2")
.Select
.Range("A34").Select
End With
ActiveSheet.Paste
Source.Close SaveChanges:=True
End Function
Please advice as I'm new in VBA