I keep getting error91 come up when I run my code which says that the object variable is not set.
It highlights the line:
'If OptionButton3.Value Then' when I try the debugger. I don't understand where its going wrong and I don't know what an object variable is? Has anyone else had this issue?
Any help would be much appreciated. Thank you
Sub NewEntry()
Dim cboOpName As Object
Dim TextBox1 As Object
Dim Operator As String
Dim UserForm1 As Object
Dim OptionButton1 As Object
Dim OptionButton3 As Object
Dim OptionButton11 As Object
Sheets("Sheet1").Activate
txtTitle1 = "Input Operator"
firstline1 = "Operator" & Chr(10) & Chr(10)
firstline = (firstline1)
Oper = InputBox(firstline, txtTitle1)
If Oper = "" Then
Exit Sub
Else
End If
If Oper = 0 Then
Exit Sub
Else
End If
txtTitle1 = "Input Project ID Number"
firstline3 = "Project ID No" & Chr(10) & Chr(10)
firstline = (firstline3)
PROno = InputBox(firstline, txtTitle1)
If PROno = "" Then
Exit Sub
Else
End If
If PROno = 0 Then
Exit Sub
Else
End If
txtTitle1 = "Input Date of Manufacture"
firstline3 = "Date of Manufacture" & Chr(10) & Chr(10)
firstline = (firstline3)
val1 = "DD/MM/YY"
DateM = InputBox(firstline, txtTitle1, val1)
If DateM = "" Then
Exit Sub
Else
End If
If DateM = 0 Then
Exit Sub
Else
End If
txtTitle1 = "Input Serial Number"
firstline3 = "Serial Number" & Chr(10) & Chr(10)
firstline = (firstline3)
SerNo = InputBox(firstline, txtTitle1)
If SerNo = "" Then
Exit Sub
Else
End If
If SerNo = 0 Then
Exit Sub
Else
End If
txtTitle1 = "Input Actuator ID"
firstline3 = "Actuator ID" & Chr(10) & Chr(10)
firstline = (firstline3)
ActID = InputBox(firstline, txtTitle1)
If ActID = "" Then
Exit Sub
Else
End If
If ActID = 0 Then
Exit Sub
Else
End If
txtTitle1 = "Input Opening Angle"
firstline3 = "Opening Angle" & Chr(10) & Chr(10)
firstline = (firstline3)
Angle = InputBox(firstline, txtTitle1)
If Angle = "" Then
Exit Sub
Else
End If
If Angle = 0 Then
Exit Sub
Else
End If
txtTitle1 = "Input Date of Test"
firstline3 = "Date of Test" & Chr(10) & Chr(10)
firstline = (firstline3)
DateT = InputBox(firstline, txtTitle1, val1)
val1 = "DD/MM/YY"
If DateT = "" Then
Exit Sub
Else
End If
If DateT = 0 Then
Exit Sub
Else
End If
UserForm2.Show
UserForm4.Show
Sheets("Sheet1").Activate
RowNow = 6
RowNum = 1
Do While RowNow = ""
If RowNow <> "" Then
RowNow = RowNow + 1
RowNum = RowNum + 1
Else
Cells(RowNow, 1).Value = RowNum
Cells(RowNow, 4).Value = PROno
Cells(RowNow, 9).Value = DateM
Cells(RowNow, 7).Value = SerNo
Cells(RowNow, 8).Value = ActID
Cells(RowNo, 2).Value = DateT
Cells(RowNow, 3).Value = Oper
Cells(RowNow, 10).Value = Angle
End If
Loop
Do While Cells(RowNow, 11) = ""
If OptionButton3.Value Then
Cells(RowNow, 11).Value = "Yes"
End If
Cells(RowNow, 11).Value = "No"
RowNow = RowNow + 1
Loop
Do While Cells(RowNow, 6) = ""
If OptionButton11.Value Then
Cells(RowNow, 6).Value = "Yes"
End If
Cells(RowNow, 6).Value = "No"
RowNow = RowNow + 1
Loop
Do While Cells(RowNow, 5) = ""
If OptionButton1.Value Then
Cells(RowNow, 5).Value = "Yes"
End If
Cells(RowNow, 5).Value = "No"
RowNow = RowNow + 1
Loop
End Sub
Related
I would need help on how to revise the code below. I was able to create the template to enter all the informations needed in the userform when the header is in row 1 on the template. But when I need to relocate the header to row 29. It doesn't work as expected even though I did revised the coded to match with row 29. Please help.
This is a good picture of the header in row1 with the code below. It is working fine.
here is the file https://1drv.ms/x/s!AixhKuqjnB1cgW8qhYoRMmt0oN0o?e=W52afT
You will find "Original" Tab. with the original VBA coding working with header in row 1. The "CID" tab will be the one I need to revise the code to work with the header moved to row 29.
This is the original code that work with header in row 1
Sub Refresh_Data()
Dim sh As Worksheet
Set sh = ThisWorkbook.Sheets("Original")
Dim last_row As Long
last_row = Application.WorksheetFunction.CountA(sh.Range("A:A"))
With Me.ListBox1
.ColumnHeads = True
.ColumnCount = 12
.ColumnWidths = "30,100,100,70,100,100,50,100,50,50,120,200"
If last_row = 1 Then
.RowSource = "Original!A2:L2"
Else
.RowSource = "Original!A2:L" & last_row
End If
End With
End Sub
Private Sub Add_Click()
Dim sh As Worksheet
Set sh = ThisWorkbook.Sheets("Original")
Dim last_row As Long
last_row = Application.WorksheetFunction.CountA(sh.Range("A:A"))
'Validations---------------------------------------------------------------------------------------
If Me.TextBox1.Value = "" Then
MsgBox "Please Fill Signal Name. If it is not required, fill -", vbCritical
Exit Sub
End If
'------------------
If Me.TextBox2.Value = "" Then
MsgBox "Please Fill (From) Connector REF DES", vbCritical
Exit Sub
End If
'------------------
If Me.TextBox3.Value = "" Then
MsgBox "Please Fill (From) Connector Pin Location", vbCritical
Exit Sub
End If
'------------------
If Me.TextBox4.Value = "" Then
MsgBox "Please Fill Contact P/N or Supplied with Connector", vbCritical
Exit Sub
End If
'------------------
If Me.TextBox5.Value = "" Then
MsgBox "Please Fill Wire Gauge", vbCritical
Exit Sub
End If
'------------------
If Me.TextBox6.Value = "" Then
MsgBox "Please Fill Wire/Cable P/N", vbCritical
Exit Sub
End If
'------------------
If Me.TextBox7.Value = "" Then
MsgBox "Please Fill (To) Connector REF DES", vbCritical
Exit Sub
End If
'------------------
If Me.TextBox8.Value = "" Then
MsgBox "Please Fill (To) Pin Location", vbCritical
Exit Sub
End If
'------------------
If Me.TextBox9.Value = "" Then
MsgBox "Please Fill Contact P/N or Supplied with Connector", vbCritical
Exit Sub
End If
'------------------
If Me.ComboBox10.Value = "" Then
MsgBox "Use Drop Down Arrow to Select Wire Color", vbCritical
Exit Sub
End If
'--------------------------------------------------------------------------------------------------
sh.Range("A" & last_row + 1).Value = "=Row()-1"
sh.Range("B" & last_row + 1).Value = Me.TextBox1.Value
sh.Range("C" & last_row + 1).Value = Me.TextBox2.Value
sh.Range("D" & last_row + 1).Value = Me.TextBox3.Value
sh.Range("E" & last_row + 1).Value = Me.TextBox4.Value
sh.Range("F" & last_row + 1).Value = Me.TextBox5.Value
sh.Range("G" & last_row + 1).Value = Me.TextBox6.Value
sh.Range("H" & last_row + 1).Value = Me.TextBox7.Value
sh.Range("I" & last_row + 1).Value = Me.TextBox8.Value
sh.Range("J" & last_row + 1).Value = Me.TextBox9.Value
sh.Range("K" & last_row + 1).Value = Me.ComboBox10.Value
sh.Range("L" & last_row + 1).Value = Me.TextBox11.Value
'------------------
Me.TextBox1.Value = ""
Me.TextBox2.Value = ""
Me.TextBox3.Value = ""
Me.TextBox4.Value = ""
Me.TextBox5.Value = ""
Me.TextBox6.Value = ""
Me.TextBox7.Value = ""
Me.TextBox8.Value = ""
Me.TextBox9.Value = ""
Me.ComboBox10.Value = ""
Me.TextBox11.Value = ""
'------------------
Call Refresh_Data
End Sub""
And this is the picture of the header moved to row 29.
Use a constant for the header row and then it's easy to change in the future.
Option Explicit
Const HEADER = 29
Private Sub CommandButton1_Click()
Dim sh As Worksheet
Set sh = ThisWorkbook.Sheets("CID")
Dim last_row As Long
last_row = sh.Cells(Rows.Count, "A").End(xlUp).Row
If last_row < HEADER Then
last_row = HEADER
End If
Dim arMsg(10) As String, n As Integer, msg As String
arMsg(1) = "Signal Name. If it is not required, fill -"
arMsg(2) = "(From) Connector REF DES"
arMsg(3) = "(From) Connector Pin Location"
arMsg(4) = "Contact P/N or Supplied with Connector"
arMsg(5) = "Wire Gauge"
arMsg(6) = "Wire/Cable P/N"
arMsg(7) = "(To) Connector REF DES"
arMsg(8) = "(To) Pin Location"
arMsg(9) = "Contact P/N or Supplied with Connector"
arMsg(10) = "Use Drop Down Arrow to Select Wire Color"
For n = 1 To 9
If Me.Controls("TextBox" & n).Value = "" Then
msg = msg & vbLf & n & ") " & arMsg(n)
End If
Next
If Me.Controls("ComboBox10").Value = "" Then
msg = msg & vbLf & arMsg(10)
End If
If Len(msg) > 0 Then
MsgBox "Please Fill " & msg, vbCritical
Exit Sub
End If
Dim c As Control
With sh.Range("A" & last_row + 1)
.Offset(0, 0).Value = "=Row()-" & HEADER
For n = 1 To 11
If n = 10 Then
Set c = Me.Controls("ComboBox" & n)
Else
Set c = Me.Controls("TextBox" & n)
End If
.Offset(0, n).Value = c.Value
c.Value = ""
Next
End With
Call Refresh_Data(sh)
End Sub
Sub Refresh_Data(sh As Worksheet)
Dim last_row As Long
last_row = sh.Cells(Rows.Count, "A").End(xlUp).Row
With Me.ListBox1
.ColumnHeads = True
.ColumnCount = 12
.ColumnWidths = "30,100,100,70,100,100,50,100,50,50,120,200"
If last_row <= HEADER Then
last_row = HEADER + 1
End If
.RowSource = sh.Name & "!A" & HEADER + 1 & ":L" & last_row
End With
End Sub
I have created a UserForm named blocksForm inside a workbook. Buttons inside the form will populate a sheet BBG with data from form. I want the form to be able to show even if my BBG sheet is not blank and fill in the next blank cell. My form will only load from the command button click when the BBG sheet is blank.
When the sheet is not blank and I click the command button to load the form, I get the 1004 error and the debugger highlights Load blocksForm from my code
Private Sub blocksSorter_Click()
Load blocksForm
blocksForm.Show
End Sub
I'm assuming the issue might be from my initialize form code below, but I can't pin point it
Public Sub UserForm_Initialize()
With Worksheets("DATA")
lRow = .Range("A" & .Rows.Count).End(xlUp).Row
End With
With Worksheets("BBG")
lastRow = .Range("A" & .Rows.Count).End(xlUp).Row
End With
MsgBox (lastRow)
If Worksheets("BBG").Range("A1") = "" And i < 3 Then
i = 2
End If
activeCheck.Value = False
itwCheck.Value = False
yestCheck.Value = False
recentCheck.Value = False
TextBox2.Value = ""
ric = Worksheets("DATA").Range("H" & i)
name = Worksheets("DATA").Range("B" & i)
valueUSD = Worksheets("DATA").Range("C" & i)
adV = Worksheets("DATA").Range("D" & i)
sitchStr = ""
dstr = ""
timeStr = ""
pStr = ric & " " & name & " " & valueUSD & " " & adV
Label1.Caption = pStr
If i > lRow Then
Unload Me
Application.Worksheets("BBG").Activate
End If
End Sub
My public variables
Public valueUSD, name, ric, adV, dstr, sitchStr, timeStr, pStr As String
Public i, lRow, lastRow, j, k As Long
The rest of my code
Private Sub activeCheck_Change()
If activeCheck.Value = True Then
sitchStr = activeCheck.Caption
dstr = dstr + sitchStr
Else
sitchStr = ""
End If
End Sub
Private Sub itwCheck_Change()
If activeCheck.Value = False And itwCheck.Value = True Then
sitchStr = sitchStr + itwCheck.Caption
dstr = dstr + sitchStr
ElseIf activeCheck.Value = True And itwCheck.Value = True Then
MsgBox ("You can only be active OR ITW")
End If
End Sub
Private Sub yestCheck_Change()
If yestCheck.Value = True Then
timeStr = timeStr & " " & yestCheck.Caption
dstr = dstr + timeStr
End If
End Sub
Private Sub recentCheck_Change()
If yestCheck.Value = False And recentCheck.Value = True Then
timeStr = timeStr & " " & recentCheck.Caption
dstr = dstr + timeStr
ElseIf yestCheck.Value = True And recentCheck.Value = True Then
MsgBox ("You cannot select both yesterday and recently")
End If
End Sub
Private Sub TextBox2_Change()
If sitchStr = "" Then
dstr = TextBox2.Value
ElseIf sitchStr <> "" Then
dstr = sitchStr & timeStr & ", " & TextBox2.Value
End If
End Sub
Private Sub addBtn_Click()
Application.ScreenUpdating = False
Dim pasteSheet As Worksheet
Set pasteSheet = Application.Worksheets("SHANE FOR BBG")
If j = 0 Then j = 1
If Worksheets("BBG").Range("A1") = "" Then
k = 1
ElseIf Worksheets("BBG").Range("A1") <> "" Then
With Worksheets("BBG")
lastRow = .Range("A" & .Rows.Count).End(xlUp).Row
End With
j = lastRow + 2
End If
If Not IsError(Application.Match(name, Sheets("BBG").Range("A:A"), 0)) Then
MsgBox ("This is already on your list")
End If
pasteSheet.Cells(j, k) = name
pasteSheet.Cells(j, k + 1) = "(" & ric & ")"
pasteSheet.Cells(j + 1, k) = valueUSD & ","
pasteSheet.Cells(j + 1, k + 1) = " " & adV & " ADV"
If dstr = "" Then
j = j + 3
ElseIf dstr <> "" Then
pasteSheet.Cells(j + 2, k) = dstr
j = j + 4
End If
i = i + 1
UserForm_Initialize
End Sub
Private Sub skipBtn_Click()
If i = 2 Then
i = 3
Else
i = i + 1
End If
UserForm_Initialize
End Sub
Private Sub prevBtn_Click()
i = i - 1
MsgBox (dstr)
UserForm_Initialize
End Sub
Sub exitBtn_Click()
Unload Me
End Sub
You could include an IF statement to prevent the error, but that wont fix the underlying problem of how i got set to 0 in the first place...
If i = 0 Then
Msgbox "Somehow, i got set to zero. Aborting."
Exit Sub
Else
ric = Worksheets("DATA").Range("H" & i)
name = Worksheets("DATA").Range("B" & i)
valueUSD = Worksheets("DATA").Range("C" & i)
adV = Worksheets("DATA").Range("D" & i)
End If
Why when I want to debug, it will error at
If Emp8.Value = True Then
str = "Whatsapp, "
End If
and it will appear;
Argument not optional
Basically what I want to do is, I want to edit data in the user form.
Private Sub cmdEdit_Click()
If Me.Emp1 = "" Then
Call MsgBox("The fields are not complete", vbInformation, "Edit Contact")
Exit Sub
End If
Set findvalue = Sheet1.Range("b8:b10000").Find(What:=Me.Emp1, LookIn:=xlValues)
findvalue.Offset(0, 1).Value = Me.Emp1.Value
If Emp8.Value = True Then
str = "Whatsapp, "
End If
If Emp12.Value = True Then
str = str & "SMS, "
End If
If Emp11.Value = True Then
str = str & "Email, "
End If
If Emp10.Value = True Then
str = str & "Facebook, "
End If
If Emp9.Value = True Then
str = str & "Phone Call, "
End If
str = Left(str, Len(str) - 2)
findvalue.Offset(0, 2) = str
If Emp2.Value = True Then
findvalue.Offset(0, 3) = "Yes"
ElseIf Emp3.Value = True Then
findvalue.Offset(0, 3) = "No"
End If
findvalue.Offset(0, 4).Value = Me.Emp4.Value
findvalue.Offset(0, 5).Value = Me.Emp5.Value
findvalue.Offset(0, 6).Value = Me.Emp6.Value
findvalue.Offset(0, 7).Value = Me.Emp7.Value
Call MsgBox("The contact has been updated", vbInformation, "Edit Contact")
On Error GoTo 0
Exit Sub
End Sub
I don't know how to program in this language so I have to rely on Google. Taken bits from here and there and I suspect that I have two puzzles that don't fit at the moment. I am getting runtime error 9 subscript out of range because of this line:
ThisWorkbook.Sheets("Sheet4").Range("c2").End(xlDown).Select = myVar
Here's my code:
Dim iRow As Long
Dim ws As Worksheet
Set ws = Worksheets("Skráningar")
'Taeki gögn í gagnagrunn
myVar = ""
For X = 0 To Me.taeki.ListCount - 1
If Me.taeki.Selected(X) Then
If myVar = "" Then
myVar = Me.taeki.List(X, 0)
Else
myVar = myVar & "," & Me.taeki.List(X, 0)
End If
End If
Next X
ThisWorkbook.Sheets("Sheet4").Range("c2").End(xlDown).Select = myVar
'find first empty row in database
'iRow = ws.Cells.Find(What:="*", SearchOrder:=xlRows, _ SearchDirection:=xlPrevious, LookIn:=xlValues).Row + 1
iRow = ws.Cells(ws.Rows.Count, "A").End(xlUp).Row + 1
'check for a Name number
If Trim(Me.timutbox.Value) = "" Then
Me.dagsbox.SetFocus
MsgBox "Vinsamlega skráðu hversu lengi tækið var í notkun"
Exit Sub
End If
Me.Hide
'copy the data to the database
ws.Cells(iRow, 1).Value = Me.dagsbox.Value
ws.Cells(iRow, 2).Value = Me.timutbox.Value
ws.Cells(iRow, 5).Value = Me.sandbox.Value
ws.Cells(iRow, 6).Value = Me.vedurbox.Value
ws.Cells(iRow, 8).Value = Me.bilunbox.Value
ws.Cells(iRow, 7).Value = Me.athbox.Value
ws.Cells(iRow, 3).Value = Me.taeki.Value
ws.Cells(iRow, 4).Value = Me.svaedi.Value
MsgBox "Data added", vbOKOnly + vbInformation, "Data Added"
'clear the data
Me.dagsbox.Value = ""
Me.timutbox.Value = ""
Me.sandbox.Value = ""
Me.vedurbox.Value = ""
Me.bilunbox.Value = ""
Me.athbox.Value = ""
Me.taeki.Value = ""
Me.svaedi.Value = ""
Me.dagsbox.SetFocus
I think I understand what you are trying to do:
Dim iRow As Long
Dim ws As Worksheet
Set ws = Worksheets("Skráningar")
'Taeki gögn í gagnagrunn
myVar = ""
For X = 0 To Me.taeki.ListCount - 1
If Me.taeki.Selected(X) Then
If myVar = "" Then
myVar = Me.taeki.List(X, 0)
Else
myVar = myVar & "," & Me.taeki.List(X, 0)
End If
End If
Next X
'find first empty row in database
'iRow = ws.Cells.Find(What:="*", SearchOrder:=xlRows, _ SearchDirection:=xlPrevious, LookIn:=xlValues).Row + 1
iRow = ws.range("A" & rows.count).End(xlUp).Row + 1
ws.Range("C" & iRow).value = myVar
'check for a Name number
If Trim(Me.timutbox.Value) = "" Then
Me.dagsbox.SetFocus
MsgBox "Vinsamlega skráðu hversu lengi tækið var í notkun"
Exit Sub
End If
Me.Hide
'copy the data to the database
ws.Cells(iRow, 1).Value = Me.dagsbox.Value
ws.Cells(iRow, 2).Value = Me.timutbox.Value
ws.Cells(iRow, 5).Value = Me.sandbox.Value
ws.Cells(iRow, 6).Value = Me.vedurbox.Value
ws.Cells(iRow, 8).Value = Me.bilunbox.Value
ws.Cells(iRow, 7).Value = Me.athbox.Value
ws.Cells(iRow, 3).Value = Me.taeki.Value
ws.Cells(iRow, 4).Value = Me.svaedi.Value
MsgBox "Data added", vbOKOnly + vbInformation, "Data Added"
'clear the data
Me.dagsbox.Value = ""
Me.timutbox.Value = ""
Me.sandbox.Value = ""
Me.vedurbox.Value = ""
Me.bilunbox.Value = ""
Me.athbox.Value = ""
Me.taeki.Value = ""
Me.svaedi.Value = ""
Me.dagsbox.SetFocus
EDIT:
I have changed how iRow is calculated, and removed reference to sheet4
Does that do what you need?
Dim iRow As Long
Dim ws As Worksheet
Set ws = Worksheets("Skráningar")
'Taeki gögn í gagnagrunn
myVar = ""
For X = 0 To Me.taeki.ListCount - 1
If Me.taeki.Selected(X) Then
If myVar = "" Then
myVar = Me.taeki.List(X, 0)
Else
myVar = myVar & "," & Me.taeki.List(X, 0)
End If
End If
Next X
'find first empty row in database
'iRow = ws.Cells.Find(What:="*", SearchOrder:=xlRows, _ SearchDirection:=xlPrevious, LookIn:=xlValues).Row + 1
iRow = ws.Range("A" & Rows.Count).End(xlUp).Row + 1
ws.Range("C" & iRow).Value = myVar
'check for a Name number
If Trim(Me.timutbox.Value) = "" Then
Me.dagsbox.SetFocus
MsgBox "Vinsamlega skráðu hversu lengi tækið var í notkun"
Exit Sub
End If
Me.Hide
'copy the data to the database
ws.Cells(iRow, 1).Value = Me.dagsbox.Value
ws.Cells(iRow, 2).Value = Me.timutbox.Value
ws.Cells(iRow, 5).Value = Me.sandbox.Value
ws.Cells(iRow, 6).Value = Me.vedurbox.Value
ws.Cells(iRow, 8).Value = Me.bilunbox.Value
ws.Cells(iRow, 7).Value = Me.athbox.Value
ws.Cells(iRow, 3).Value = Me.taeki.Value
ws.Cells(iRow, 4).Value = Me.svaedi.Value
MsgBox "Data added", vbOKOnly + vbInformation, "Data Added"
'clear the data
Me.dagsbox.Value = ""
Me.timutbox.Value = ""
Me.sandbox.Value = ""
Me.vedurbox.Value = ""
Me.bilunbox.Value = ""
Me.athbox.Value = ""
Me.taeki.Value = ""
Me.svaedi.Value = ""
Me.dagsbox.SetFocus
This is the current code.
When I execute the following code, a black command window opens and it will flicker until the time all devices pings. How can I run it silently?
Sub PING()
Application.ScreenUpdating = False
Dim strTarget, strPingResult, strInput, wshShell, wshExec
With Sheets(1)
shlastrow = .Cells(Rows.Count, "B").End(xlUp).Row
Set shrange = .Range("B3:B7" & shlastrow)
End With
For Each shCell In shrange
strInput = shCell.Text
If strInput <> "" Then
strTarget = strInput
setwshshell = CreateObject("wscript.shell")
Set wshExec = wshShell.exec("ping -n 2 -w 5 " & strTarget)
strPingResult = LCase(wshExec.stdout.readall)
If InStr(strPingResult, "reply from") Then
shCell.Offset(0, 1).Value = "Reachable"
shCell.Offset(0, 2).Value = "Time"
Else
shCell.Offset(0, 1).Value = "UnReachable"
shCell.Offset(0, 2).Value = "Reachable"
End If
End If
Next shCell
End Sub
Here is the code for that
Sub Do_ping()
With ActiveWorkbook.Worksheets(1)
n = 0
Row = 2
Do
If .Cells(Row, 1) <> "" Then
If IsConnectible(.Cells(Row, 1), 2, 100) = True Then
n = n + 1
Cells(Row, 1).Interior.Color = RGB(0, 255, 0)
Cells(Row, 1).Font.FontStyle = "bold"
Cells(Row, 1).Font.Size = 14
Cells(Row, 2).Interior.Color = RGB(0, 255, 0)
Cells(Row, 2).Value = Time
'Call siren
Else:
n = n + 1
'Cells(Row, 2).Formula = "=NOW()-" & CDbl(Now())
Cells(Row, 1).Interior.Color = RGB(255, 0, 0)
Cells(Row, 3).Value = DateDiff("h:mm:ss", Cells(Row, 2), Now())
End If
End If
Row = Row + 1
Loop Until .Cells(Row, 1) = ""
End With
End Sub
Function IsConnectible(sHost, iPings, iTO)
' Returns True or False based on the output from ping.exe
' Works an "all" WSH versions
' sHost is a hostname or IP
' iPings is number of ping attempts
' iTO is timeout in milliseconds
' if values are set to "", then defaults below used
Dim nRes
If iPings = "" Then iPings = 1 ' default number of pings
If iTO = "" Then iTO = 550 ' default timeout per ping
With CreateObject("WScript.Shell")
nRes = .Run("%comspec% /c ping.exe -n " & iPings & " -w " & iTO _
& " " & sHost & " | find ""TTL="" > nul 2>&1", 0, True)
End With
IsConnectible = (nRes = 0)
End Function