+ Reply to Thread
Results 1 to 3 of 3

Beginner: perplexed by Type Mismatch

Hybrid View

  1. #1
    Registered User
    Join Date
    08-15-2013
    Location
    london
    MS-Off Ver
    Excel 2013
    Posts
    1

    Beginner: perplexed by Type Mismatch

    Dear all,

    Please see attached code. I'm sorry for including some unnecessary variables but for some reason I cannot replicate the error by excluding them.

    Line 28 gives a Type Mismatch error. I am perplexed by this as Line 24 (added just as a debugging test) which should do exactly the same does pass without an exception. Why does it work outside the loop but not inside the loop?!

    1 Private Sub CommandButton1_Click()
    2 Dim numCampaigns As Long
    3 Dim rangeCampaigns As Range
    4 Set rangeCampaigns = Worksheets(6).Range("A:A")
    5 numCampaigns = Application.WorksheetFunction.CountA(rangeCampaigns)
    6 
    7 Dim numOrders As Long
    8 Dim rangeOrders As Range
    9 Set rangeOrders = Worksheets(1).Range("A:A")
    10 numOrders = Application.WorksheetFunction.CountA(rangeOrders)
    11 
    12 Dim orderEDM() As Integer
    13 Dim orderCampaign() As String
    14 Dim orderBU() As String
    15 Dim orderDate() As Double
    16 
    17 ReDim orderEDM(numOrders - 1, 1) As Integer
    18 ReDim orderCampaign(numOrders - 1, 1) As String
    19 ReDim orderBU(numOrders - 1, 1) As String
    20 ReDim orderDate(numOrders - 1, 1) As Double
    21 
    22 Dim i As Long
    23 
    24 orderCampaign(0, 1) = Cells(2, 9)
    25 
    26 For i = 0 To numOrders - 2
    27     orderEDM(i, 1) = Cells(i + 2, 15)
    28     orderCampaign(i, 1) = Cells(i + 2, 9)
    29     orderBU(i, 1) = Cells(i + 2, 14)
    30 Next i
    Many thanks in advance

  2. #2
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    48,266

    Re: Beginner: perplexed by Type Mismatch

    See if changing this

    12 Dim orderEDM() As Integer
    13 Dim orderCampaign() As String
    14 Dim orderBU() As String
    15 Dim orderDate() As Double
    16 
    17 ReDim orderEDM(numOrders - 1, 1) As Integer
    18 ReDim orderCampaign(numOrders - 1, 1) As String
    19 ReDim orderBU(numOrders - 1, 1) As String
    20 ReDim orderDate(numOrders - 1, 1) As Double

    To this helps

    12 Dim orderEDM()
    13 Dim orderCampaign()
    14 Dim orderBU()
    15 Dim orderDate()
    16 
    17 ReDim orderEDM(numOrders - 1, 1)
    18 ReDim orderCampaign(numOrders - 1, 1)
    19 ReDim orderBU(numOrders - 1, 1)
    20 ReDim orderDate(numOrders - 1, 1)

    Regards, TMS
    Trevor Shuttleworth - Retired Excel/VBA Consultant

    I dream of a better world where chickens can cross the road without having their motives questioned

    'Being unapologetic means never having to say you're sorry' John Cooper Clarke


  3. #3
    Forum Expert romperstomper's Avatar
    Join Date
    08-13-2008
    Location
    England
    MS-Off Ver
    365, varying versions/builds
    Posts
    21,982

    Re: Beginner: perplexed by Type Mismatch

    Is there an error in Cells(i + 2, 9) perhaps?
    Everyone who confuses correlation and causation ends up dead.

+ 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. 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. 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