473,565 Members | 2,770 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Nu 2 VB -- Type Mismatch Error

1 New Member
I inherited an Excel spreadsheet with a macro that is giving me a type mismatch error on the line with 'If Cells(I, 1) <> "" Then'. I believe the programming is looking for a variable when the accompanying spreadsheet only contains text. If this is true, how do I resolve?

Expand|Select|Wrap|Line Numbers
  1. Dim Risks(20) As String
  2. Dim LH(20), Impact(20), Response(20), Trend(20), Change(20), NR(20), Del(20), XY(3, 3), XAxis(3, 3) As Integer
  3. Dim I, J, K, Flag, HI, MI, LI, RMax, Total, X, Y As Integer
  4.  
  5.  
  6. I = 10
  7. J = 1
  8. Flag = 0
  9. LI = 0
  10. MI = 0
  11. HI = 0
  12.  
  13. X = 1
  14. Y = 1
  15. While X <= 3
  16.     While Y <= 3
  17.         XY(X, Y) = 0
  18.         XAxis(X, Y) = 0
  19.         Y = Y + 1
  20.     Wend
  21.     Y = 1
  22.     X = X + 1
  23. Wend
  24.  
  25.  
  26. While Flag = 0
  27.  
  28.     Sheets("Inputs").Select
  29.  
  30.     If Cells(I, 1) <> "" Then
  31.  
  32.             Risks(J) = Cells(I, 1)
  33.             LH(J) = Cells(I, 2)
  34.             Impact(J) = Cells(I, 3)
  35.  
  36.             XY(LH(J), Impact(J)) = XY(LH(J), Impact(J)) + 1
  37.  
  38.  
  39.             Response(J) = Cells(I, 4)
  40.             Trend(J) = Cells(I, 5)
  41.             Change(J) = Cells(I, 6)
  42.             NR(J) = Cells(I, 7)
  43.             Del(J) = Cells(I, 8)
  44.  
  45.             I = I + 1
  46.             J = J + 1
  47.                                         Else
  48.  
  49.             Flag = 1
  50.     End If
  51. Wend
  52.  
  53. Total = J - 1
  54.  
  55.  
  56. RMax = 0
  57.  
  58. X = 1
  59. Y = 1
  60.  
  61. While X <= 3
  62.     While Y <= 3
  63.         If XY(X, Y) > RMax Then
  64.             RMax = XY(X, Y)
  65.         End If
Feb 25 '08 #1
2 1280
Killer42
8,435 Recognized Expert Expert
My first thought would be, perhaps the cell in question contains a null, or an error, or even a number. Since you're comparing it to a string, the null or error would quite probably cause a problem. As for the number... maybe, maybe not. Anyway, I'd recommend you go into debug mode at the point where the error occurs, and examine the contents of Cells(I, 10).


An interesting side note is that unless this is the newer VB.Net syntax (which it certainly dodsn't look like), only XAxis() and Y are defined as Integer. All the rest (apart from Risks() which is String, of course) are defined as Variant, the default type. Were you aware of that?

I did wonder at first whether perhaps this meant that I was of the wrong type and thus producing the error. But the fact that you're placing a numeric value in it (@ line 6) probably squashes that idea.
Feb 25 '08 #2
kadghar
1,295 Recognized Expert Top Contributor
If the value of I is an integer between 1 and 65536 when you get to that line, it shouldnt give you a type mismatch, since it makes an implicit type conversion from a cell (actually a range) to a string. Anyway, explicit changing the type might be of help here:

Expand|Select|Wrap|Line Numbers
  1.     If cstr(Cells(I, 1).value) <> "" Then
HTH
Feb 26 '08 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

5
4427
by: Arun Wadhawan | last post by:
Hello MY SQL Server is causing me this problem : Microsoft VBScript runtime error '800a000d' Type mismatch: 'ident' >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> I am getting from the table datingnew the value of the ident field.
1
2484
by: LJgrnl | last post by:
I've got a type mismatch error that's driving me nutty. Variable blnNoData has the initial value False. If a recordset comes back empty (both .EOF and ..BOF are true) then blnNoData is set to True. I then have an if statement to determine what to write to the screen depending on blnNoData. As long as the if statement is true (doesn't have...
4
11952
by: Mike | last post by:
I am getting a type mismatch error when I do a bulk insert. ---Begin Error Msg--- Server: Msg 4864, Level 16, State 1, Line 1 Bulk insert data conversion error (type mismatch) for row 1, column 14 (STDCOST). ---End Error Msg--- The STDCOST is set to decimal (28,14) and is a formatted in Access as a number, single with 14 decimal. I...
0
2239
by: news.paradise.net.nz | last post by:
I have been developing access databases for over 5 years. I have a large database and I have struck this problem with it before but can find nothing in help or online. Access 2000 I have a query that will run fine without any criteria but as soon as I add any criteria it gives a "Data type mismatch" error. As soon as I remove any criteria...
3
2905
by: amitbadgi | last post by:
I am getting teh following error while converting an asp application to asp.net, Exception Details: System.Runtime.InteropServices.COMException: Type mismatch. Source Error: Line 347: 'response.Write(sql2)
1
2793
by: Brett | last post by:
I have a form that calls a method within a DLL. By clicking a button on the form, the DLL is instantiated and the SaveOutlookMessage() method invoked. The DLL code copies messages from Outlook to an HTML file. When I execute the EXE, which is only the form, and click the button, I get a "Type Mismatch" error on this line in the form:...
6
5978
by: Howard Kaikow | last post by:
I'm doing a VB 6 project in which I am trying to protect against type mismatch errors. Is the process any different in VB .NET? Here's what I'm doing in VB 6. I have an ActiveX DLL. The class has stuff initialized by calling a sub SetClass that wants some Word specific objects passed-in. If the user mistakingly uses the wrong object,...
1
1658
by: jodyblau | last post by:
I have a database which works fine until I create and MDE file. Once I create the MDE, when I open a particular form I get a "Type Mismatch" error. Because its an MDE file, I can't step through the code to find out where the error is occuring; and (as I mentioned earlier) when I go back to the oriignal database the problem doesn't exist. ...
19
5520
by: zz12 | last post by:
Hello, is there a setting in IIS 5.0 that would quickly fix the following error?: Microsoft VBScript runtime (0x800A000D) Type mismatch It's strange because some of our .asp pages were working fine for the past years but recently our website was updated in that old folders were renamed and the new ones took on the existing name and was...
1
2821
by: nckinfutz | last post by:
hello, I am having a problem with an access database. this is not my database and I did not create it, nor am I very good at access. however, I am a network engineer and that is why this problem has ended up in my lap i guess. This is the issue: There is an access database that pulls data from a list of excel spread sheets. This access...
0
7666
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7888
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
1
7644
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
1
5484
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5213
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3643
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3626
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2083
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1201
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.