简体   繁体   English

在Excel中查找最后使用的单元格

[英]Finding the last used cell in Excel

Anyone knows how to check if the cell contains a data using VBScript? 有谁知道如何使用VBScript检查单元格是否包含数据? Because of what I have seen, it's a bit differrent from VBA. 由于我所见,它与VBA有所不同。 I have tried this code but is not working: 我已经尝试过此代码,但无法正常工作:

Set objExcel = CreateObject("Excel.Application")
Set objWorkbook = objExcel.Workbooks.Open("C:\test\test.xlsx")
Set user = CreateObject("WScript.Network")
logname = user.Username

objExcel.Application.Visible = True

If Hour(Now) >= 1 And Hour(Now) =< 11 Then
    WScript.Echo "Good Morning"
    WScript.Echo "Log Record is:", Time, Date

    lastrow = Range("A1").End(xlDown).Row
    Cells(lastrow+1, 1).Value = logname
End If

After checking if the row contains a data, the code will insert data to the next row that doesn't contain a data. 检查该行是否包含数据后,代码会将数据插入不包含数据的下一行。 We'll say: if CELL A1 has a data, then CELL A2 is empty, then the data to be inserted will be inserted in CELL A2 . 我们将说:如果CELL A1有数据,则CELL A2为空,则要插入的数据将插入CELL A2

Please note that I'm working on , not . 请注意,我正在使用而不是

Use the UsedRange property: 使用UsedRange属性:

Set ws = objExcel.ActiveSheet

With ws.UsedRange
  nextrow = .Row + .Rows.Count
End With

Set cell = ws.Cells(nextrow, 1).Range("A1")

cell.Value = logname

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM