你好我正在制作一个宏来绘制一些数据,关键是要从用户那里接收两列来绘制,我试着先用两个输入框得到这个值:
first = InputBox("first column", "Enter a Column")
two = InputBox("second column", "Enter a Column")
这种方法的问题在于我必须执行以下操作才能绘制:
Set rng = .Range(first + "2:" + first + "84," + two + "2:" + two + "84")
我们的想法是接收价值 将它与" 2"连接起来和" 84"这是我的范围, 我想让这个宏更灵活,因为我总是使用2到84的相同范围,我不理解非常活跃的列,我想感谢任何克服这种情况的建议,我的完整代码看起来如下:
Sub ALL()
Dim ws As Worksheet
Dim rng As Range
Dim objChrt As ChartObject
Dim chrt As Chart
Set ws = ThisWorkbook.Sheets("DATA")
With ws
first = InputBox("first column", "Enter a Column")
two = InputBox("second column", "Enter a Column")
Set rng = .Range(first + "2:" + first + "84," + two + "2:" + two + "84")
.Shapes.AddChart
Set objChrt = .ChartObjects(.ChartObjects.Count)
Set chrt = objChrt.Chart
With chrt
.ChartType = xlColumnClustered
.SetSourceData Source:=rng
End With
End With
End Sub
答案 0 :(得分:1)
我仍然不明白这个问题所以也许图片或例子可能会有所帮助 获得列范围的另一种方法是这样的
Set rng = ThisWorkbook.Sheets("DATA").Range("C2:C84")
MsgBox rng.Columns("B").Address(0, 0) ' D2:D84
MsgBox rng.Columns(-1 ).Address(0, 0) ' A2:A84
MsgBox Union( rng.Columns(2), rng.Columns(4) ).Address(0, 0) ' D2:D84,F2:F84
如果数据位于B2:D4
范围内且周围只有空白单元格,那么您可以使用Range("C3").CurrentRegion