phamvandunghp84
Thành viên thường trực




- Tham gia
- 5/3/20
- Bài viết
- 241
- Được thích
- 12
Các bạn ơi cho mình hỏi mình có đoạn code này vẫn chạy bình thường nhưng nay mình muốn thay thế ô b1,b4 cố định thành ô động thì làm như nào ? Nhờ các bạn giúp đỡ!
Sub gan_gia_tri_cho_Bieu_Do()
Dim i As Integer
For i = 1 To 7
ActiveSheet.ChartObjects(i).Activate
ActiveChart.SeriesCollection(1).Formula = _
rpl(ActiveChart.SeriesCollection(1).Formula, [b1].Offset(, i).Address, [b1:b4].Offset(, i).Address) ' muốn chuyển sang ô động (ghi chú ở dòng **). cố định ô b dịch chuyển sang i cột
Next i
End Sub
Function rpl(ByVal str As String, ByVal S_name As String, ByVal S_rng As String) As String 'ham nay de doi cong thuc cho bieu do
With CreateObject("vbscript.regexp")
.Global = True
.Pattern = "\$[^;,]+\$[^;,]+(?=[;,])"
str = Replace(str, .Execute(str)(0), S_name)
str = Replace(str, .Execute(str)(2), S_rng)
End With
rpl = str
End Function
Mình thử làm như này nhưng không thấy được, không biết do lỗi ở đâu?
Sub gan_gia_tri_cho_Bieu_Do_cot_dong()
Dim i As Integer
Dim cotdautap As Integer
For i = 1 To 7
cotdautap =2
ActiveSheet.ChartObjects(i).Activate
ActiveChart.SeriesCollection(1).Formula = _
rpl(ActiveChart.SeriesCollection(1).Formula, [cells(1,cotdautap].Offset(, 4).Address, [cells(1,cotdautap):cells(4,cotdautap)].Offset(, 4).Address) (ghi chú dòng **) . Muốn cố định số cột cần dịch sang lần lượt là 4,5 cột nhưng theo ô động, chứ cố định là cột b như trên nữa,
ActiveChart.SeriesCollection(2).Formula = _
rpl(ActiveChart.SeriesCollection(2).Formula, [cells(1,cotdautap].Offset(, 5).Address, [cells(1,cotdautap):cells(4,cotdautap)].Offset(, 5).Address)
End Sub
Sub gan_gia_tri_cho_Bieu_Do()
Dim i As Integer
For i = 1 To 7
ActiveSheet.ChartObjects(i).Activate
ActiveChart.SeriesCollection(1).Formula = _
rpl(ActiveChart.SeriesCollection(1).Formula, [b1].Offset(, i).Address, [b1:b4].Offset(, i).Address) ' muốn chuyển sang ô động (ghi chú ở dòng **). cố định ô b dịch chuyển sang i cột
Next i
End Sub
Function rpl(ByVal str As String, ByVal S_name As String, ByVal S_rng As String) As String 'ham nay de doi cong thuc cho bieu do
With CreateObject("vbscript.regexp")
.Global = True
.Pattern = "\$[^;,]+\$[^;,]+(?=[;,])"
str = Replace(str, .Execute(str)(0), S_name)
str = Replace(str, .Execute(str)(2), S_rng)
End With
rpl = str
End Function
Mình thử làm như này nhưng không thấy được, không biết do lỗi ở đâu?
Sub gan_gia_tri_cho_Bieu_Do_cot_dong()
Dim i As Integer
Dim cotdautap As Integer
For i = 1 To 7
cotdautap =2
ActiveSheet.ChartObjects(i).Activate
ActiveChart.SeriesCollection(1).Formula = _
rpl(ActiveChart.SeriesCollection(1).Formula, [cells(1,cotdautap].Offset(, 4).Address, [cells(1,cotdautap):cells(4,cotdautap)].Offset(, 4).Address) (ghi chú dòng **) . Muốn cố định số cột cần dịch sang lần lượt là 4,5 cột nhưng theo ô động, chứ cố định là cột b như trên nữa,
ActiveChart.SeriesCollection(2).Formula = _
rpl(ActiveChart.SeriesCollection(2).Formula, [cells(1,cotdautap].Offset(, 5).Address, [cells(1,cotdautap):cells(4,cotdautap)].Offset(, 5).Address)
End Sub