+ Reply to Thread
Results 1 to 5 of 5

Type mismatch

Hybrid View

aman1234 Type mismatch 09-09-2014, 11:32 AM
Speshul Re: Type mismatch 09-09-2014, 11:34 AM
AB33 Re: Type mismatch 09-09-2014, 11:41 AM
Speshul Re: Type mismatch 09-09-2014, 11:43 AM
AB33 Re: Type mismatch 09-09-2014, 11:52 AM
  1. #1
    Forum Contributor
    Join Date
    02-20-2009
    Location
    bristol
    MS-Off Ver
    Excel 2003
    Posts
    883

    Type mismatch

    Hi All

    I am getting Type mismatch at the following line of code. ANy help would be much appreciated.
    For i = 1 To 64
    If ws.Cells(i, "M") <> 0 Then
    ws.Cells(i, "Q").FormulaR1C1 = "=sum(" & ws.Cells(i, "Z") / ws.Cells(i, "M") & ")"
    end if
    next i
    Thanks

  2. #2
    Valued Forum Contributor
    Join Date
    01-19-2012
    Location
    Barrington, IL
    MS-Off Ver
    Excel 2007/2010
    Posts
    1,211

    Re: Type mismatch

    If ws.Cells(i, "M") <> 0 Then
    M needs to be a number I believe,


    If ws.Cells(i, 13) <> 0 Then

    (13 = the thirteenth column = Column M)

    This function and others in VBA use R1C1 format, so R=ROW number, C=COLUMN number
    ws.Cells( R , C )

    Edit: Same issue with
    ws.Cells(i, "Z")
    Try
    ws.Cells(i, 26)



    ws.Cells(i, "Q").FormulaR1C1 = "=sum(" & ws.Cells(i, 26) / ws.Cells(i, 13) & ")"
    Last edited by Speshul; 09-09-2014 at 11:40 AM.
    You should hit F5, because chances are I've edited this post at least 5 times.
    Example of Array Formulas
    Quote Originally Posted by Jacc View Post
    Sorry, your description makes no sense. I just made some formula that looks interesting cause I had nothing else to do.
    Click the * below on any post that helped you.

  3. #3
    Forum Expert
    Join Date
    03-28-2012
    Location
    TBA
    MS-Off Ver
    Office 365
    Posts
    12,454

    Re: Type mismatch

    I have run the test and did not get any error
    By the way

    If ws.Cells(i, "M") <> 0 Then
    is the same as

    If ws.Cells(i, 13) <> 0 Then
    But If ws.Cells(i, "M") <> 0 Then is more accurate as the column is hard coded.
    I suspect the error might be found in ws

  4. #4
    Valued Forum Contributor
    Join Date
    01-19-2012
    Location
    Barrington, IL
    MS-Off Ver
    Excel 2007/2010
    Posts
    1,211

    Re: Type mismatch

    I was under the impression they need to be numeric.

    Now I know!

    Thanks.


    That being the case,

    ws.Cells: What is ws declared as? Isn't a mismatch usually a result of a variable being told to be something it can't be? (assigning a string to a variable defined as a boolean, for example)
    Last edited by Speshul; 09-09-2014 at 11:46 AM.

  5. #5
    Forum Expert
    Join Date
    03-28-2012
    Location
    TBA
    MS-Off Ver
    Office 365
    Posts
    12,454

    Re: Type mismatch

    If you do not use Option Explicit at the top , VBA might treat ws as unknown variable and might now now show you an error. If you use Option Explicit, however,the code will error, as the object ,which in this case is worksheet, has not been defined.
    You need to use "set" with object variables.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Run Type error 13 Type Mismatch
    By Affan Khan in forum Excel Programming / VBA / Macros
    Replies: 15
    Last Post: 11-13-2012, 12:58 PM
  2. [SOLVED] Run-type error 13 type mismatch
    By misop in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 06-05-2012, 04:08 AM
  3. Type Mismatch: array or user defined type expected
    By ExcelMonkey in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 07-06-2006, 10:45 AM
  4. [SOLVED] Type mismatch using rnge as Range with Type 8 Input Box
    By STEVE BELL in forum Excel Programming / VBA / Macros
    Replies: 11
    Last Post: 12-03-2005, 01:10 AM
  5. [SOLVED] Help: Compile error: type mismatch: array or user defined type expected
    By lvcha.gouqizi in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 10-31-2005, 05:05 PM

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1