Anyone knows how to check if the cell contains a data using VBScript? Because of what I have seen, it's a bit differrent from 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
.
Use the UsedRange
property:
Set ws = objExcel.ActiveSheet
With ws.UsedRange
nextrow = .Row + .Rows.Count
End With
Set cell = ws.Cells(nextrow, 1).Range("A1")
cell.Value = logname
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.