我正在为某些数据创建折线图
var socket = io.connect("your.domain:3000");
我的最后一个单元格是D352,此索引因不同的纸张而异。如何通过获取最后使用的单元格索引来更改代码以使其动态工作?
答案 0 :(得分:2)
假设最后一个索引是由A列中最后一个非空单元格给出的
变化:
ActiveChart.SetSourceData Source:=Range("A2:D352")
为:
ActiveChart.SetSourceData Source:=Range("A2:D" & Cells(Rows.Count, 1).End(xlUp).Row)
答案 1 :(得分:0)
考虑一下。
Sub FindingLastRow()
'PURPOSE: Different ways to find the last row number of a range
'SOURCE: www.TheSpreadsheetGuru.com
Dim sht As Worksheet
Dim LastRow As Long
Set sht = ThisWorkbook.Worksheets("Sheet1")
'Ctrl + Shift + End
LastRow = sht.Cells(sht.Rows.Count, "A").End(xlUp).Row
'Using UsedRange
sht.UsedRange 'Refresh UsedRange
LastRow = sht.UsedRange.Rows(sht.UsedRange.Rows.Count).Row
'Using Table Range
LastRow = sht.ListObjects("Table1").Range.Rows.Count
'Using Named Range
LastRow = sht.Range("MyNamedRange").Rows.Count
'Ctrl + Shift + Down (Range should be first cell in data set)
LastRow = sht.Range("A1").CurrentRegion.Rows.Count
End Sub