返回列表 上一主題 發帖

[發問] Excel vba get dynamic range( fields) to create the line chart

回復 2# c3676816
Try to define a name of dynamic range : =OFFSET($B$1,0,0,COUNTA($B:$B),COUNTA($1:$1)-6)
Then set the source of your chart refer to this name.

TOP

本帖最後由 stillfish00 於 2014-1-3 13:43 編輯

回復 4# c3676816
  1. Sub Macro1()
  2.     Dim oReg As Object, lCol As Long
  3.    
  4.     Set oReg = CreateObject("vbscript.regexp")
  5.     oReg.Pattern = "^\d{4}/Q?\d{1,2}"
  6.       
  7.     With Sheet1
  8.       For lCol = 2 To .Range("B6").End(xlToRight).Column
  9.         If Not oReg.test(.Cells(6, lCol).Value) Then Exit For
  10.       Next
  11.       Sheet2.ChartObjects("Chart 1").Chart.SetSourceData _
  12.         Source:=.Range(.Range("A6"), .Cells(6, lCol - 1)).Resize(.Range("B6").CurrentRegion.Rows.Count), _
  13.         PlotBy:=xlRows
  14.     End With
  15. End Sub
複製代碼

TOP

        靜思自在 : 欣賞別人就是莊嚴自己。
返回列表 上一主題