Results 1 to 3 of 3

Thread: Visual Basic in Excel, Mismatch Error

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Dec 2005
    Posts
    124

    Visual Basic in Excel, Mismatch Error

    ++Hope this is the right forum++

    Now Visual Basic In excel is very odd. Its not too hard to get your head around it its just odd when reading and writting Information.

    I'm gettnig a Mismatch error when I try to read to read a number form the speardsheet and laod it as a viriable.

    Heres the code thats giveing me the error

    VB Code:
    1. 'Part of the AddRecord() Sub
    2.     Dim RecordNumber As Long
    3.     Dim index As Integer
    4.     Dim DoB As String
    5.     Dim Num As Long
    6.     index = 0
    7.     Sheets("Data").Select
    8.     [b]RecordNumber = Range("B2").Value 'This line is giving me the error[/b]
    9.     Sheets("Enter Data").Select
    10.     Num = Range("G11:I11").Value
    11.     If Num = RecordNumber Then
    12.         Else
    13.         MsgBox ("You changed the Record Number, this Record has NOT be processed")
    14.         Sheets("Data Main").Select
    15.         Exit Sub
    16.     End If

    Can anyone help me with this? I can't think of a reason for it not to work. I've uplaoded the workbook if anyone wants to check in that.

    Cheers
    --ichar
    Attached Files Attached Files

  2. #2
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: Visual Basic in Excel, Mismatch Error

    I think a question on Excel VBA would be better served here.

    In ClassicVb, you are probably going to get responses in VB6 code, which may, or may not, work from within Excel.

    Moved.

  3. #3
    old fart Frans C's Avatar
    Join Date
    Oct 1999
    Location
    the Netherlands
    Posts
    2,926

    Re: Visual Basic in Excel, Mismatch Error

    That line could return an error, if the value was not numeric.

    I tested it, but i get an error on the line:
    Num = Range("G11:I11").Value

    I had to change it to
    Num = Range("G11").Value
    to get it to work.

    You can't assign the value of 3 cells to a single variable, even if the cells are merged. You could assign it to a variant, but that would result in an array.
    You have used this on many places, so you would have to change it everywhere.
    There are many more errors in your code and in your logic, but I will leave these to you.
    Frans

Posting Permissions

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



Click Here to Expand Forum to Full Width