Consulting

Results 1 to 6 of 6

Thread: Type mismatch error on startup

  1. #1
    VBAX Newbie
    Joined
    Sep 2016
    Posts
    3
    Location

    Type mismatch error on startup

    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
    Last edited by SamT; 09-13-2016 at 08:00 AM. Reason: Used # Icon to add CODE Tags

  2. #2
    VBAX Expert
    Joined
    Aug 2004
    Posts
    810
    Location
    check to see if value is #n/a first
        If Application.IsNA(Range("A1")) Then
            MsgBox "error"
        End If

  3. #3
    VBAX Sage SamT's Avatar
    Joined
    Oct 2006
    Location
    Near Columbia
    Posts
    7,814
    Location
    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
    I expect the student to do their homework and find all the errrors I leeve in.


    Please take the time to read the Forum FAQ

  4. #4
    VBAX Newbie
    Joined
    Sep 2016
    Posts
    3
    Location
    Quote Originally Posted by SamT View Post
    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

  5. #5
    VBAX Sage SamT's Avatar
    Joined
    Oct 2006
    Location
    Near Columbia
    Posts
    7,814
    Location
    ???
    I expect the student to do their homework and find all the errrors I leeve in.


    Please take the time to read the Forum FAQ

  6. #6
    VBAX Newbie
    Joined
    Sep 2016
    Posts
    3
    Location
    Thank you!!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •