1 Attachment(s)
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:
'Part of the AddRecord() Sub
Dim RecordNumber As Long
Dim index As Integer
Dim DoB As String
Dim Num As Long
index = 0
Sheets("Data").Select
[b]RecordNumber = Range("B2").Value 'This line is giving me the error[/b]
Sheets("Enter Data").Select
Num = Range("G11:I11").Value
If Num = RecordNumber Then
Else
MsgBox ("You changed the Record Number, this Record has NOT be processed")
Sheets("Data Main").Select
Exit Sub
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
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.
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.