taykaisheng
New Member
- Joined
- Jul 30, 2013
- Messages
- 10
Hi, Could anyone teach me how to select multiple columns in CurrentRegion property so that I can create a Bar chart based on it
Below are my progress so far.. however it doesn't work
The error message i got was Application-defined or Object-defined error
The columns I wanted to select was Column A and Column C. I am unable to select the column by indicating the address of the cells such as "A34" or "C34" because the table data was generated using a program tools and thus the location of the table data is vary every time
The image below is the table data that I refer to
View image: table 1
Below are my progress so far.. however it doesn't work
Code:
Public Function FourthTable()
Dim Source As Workbook
Dim Search As Range
Dim CR 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)
Source.Worksheets("Sheet1").Range(Search.Address).Offset(2, 0).CurrentRegion.Activate
ActiveCell.CurrentRegion.Columns.Range("A:A,
C:C").Resize(ActiveCell.CurrentRegion.Rows.Count - 1).Select
ActiveSheet.Shapes.AddChart.Select
'ActiveChart.SetSourceData
Source:=ActiveWorkbook.Sheets(1).Range(Search.Address).Offset(2,
0).CurrentRegion.Resize(CR.Rows.Count - 1, CR.Columns.Count)
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
The error message i got was Application-defined or Object-defined error
The columns I wanted to select was Column A and Column C. I am unable to select the column by indicating the address of the cells such as "A34" or "C34" because the table data was generated using a program tools and thus the location of the table data is vary every time
The image below is the table data that I refer to
View image: table 1