PDA

View Full Version : [SOLVED:] Type mismatch error on startup



dmwa
09-13-2016, 04:33 AM
Im doing a little data logging, A1 is an external reference and takes a few seconds to connect. once connected and it reads the variable numerical value and the script runs fine and logs every change of value in A1. problem is when first opening the workbook the script goes into a type mismatch error because the value of A1 as not updated yet and reads #N/A. I tried using a check box to run the script but it only logs the first change and seems to not log any further changes. any help would be greatly appreciated


Private Sub Worksheet_Calculate()
Static oldval
If Range("A1").Value <> oldval Then
oldval = Range("A1").Value
Range("A3").EntireRow.Insert
Range("A1:C1").Select
Selection.Copy
Range("A3").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Application.CutCopyMode = False
Range("A31").EntireRow.Delete

End If
End Sub

JKwan
09-13-2016, 07:04 AM
check to see if value is #n/a first


If Application.IsNA(Range("A1")) Then
MsgBox "error"
End If

SamT
09-13-2016, 07:59 AM
Private Sub Worksheet_Change(ByVal Target As Range)

If Target.Address <> "$A$1" Then Exit Sub

Rows(3).Insert
Range("A1:C1").Copy Range("A3:C3")
Application.CutCopyMode = False

Rows(31).Delete

End Sub

dmwa
09-13-2016, 10:22 AM
Private Sub Worksheet_Change(ByVal Target As Range)

If Target.Address <> "$A$1" Then Exit Sub

Rows(3).Insert
Range("A1:C1").Copy Range("A3:C3")
Application.CutCopyMode = False

Rows(31).Delete

End Sub

SamT
09-13-2016, 11:34 AM
???

dmwa
09-14-2016, 03:25 AM
Thank you!!