+ Reply to Thread
Results 1 to 3 of 3

inputting a single value into a variant

  1. #1
    Registered User
    Join Date
    08-10-2012
    Location
    Washington, DC, USA
    MS-Off Ver
    Excel 2010
    Posts
    2

    inputting a single value into a variant

    I have the following code:


    Please Login or Register  to view this content.



    It works fine if citynum >= 2, but not if citynum is 1, meaning there is only one value to enter into the variant named cities. In this latter case, I get the error 'Run-time error '13': Type mismatch'. I've tried to ReDim cities to be only one value, but that didn't work. How can I get this to work? Thanks.


    Moderator's Edit: Use code tags while posting code. To do so in future, select your code and click on the # icon at the top of your post window.
    Last edited by guerrillagaurav; 12-05-2012 at 02:54 PM. Reason: correcting code

  2. #2
    Forum Expert
    Join Date
    07-15-2012
    Location
    Leghorn, Italy
    MS-Off Ver
    Excel 2010
    Posts
    3,431

    Re: inputting a single value into a variant

    try with Dim cities
    instead of Dim cities() As Variant
    If solved remember to mark Thread as solved

  3. #3
    Registered User
    Join Date
    08-10-2012
    Location
    Washington, DC, USA
    MS-Off Ver
    Excel 2010
    Posts
    2

    Re: inputting a single value into a variant

    So if I move everything inside the While loop it works fine. Below is the new code:

    Please Login or Register  to view this content.
    I'm not sure why having the range(cells()) function doesn't work, so if anyone can give a response as to why this new code works but the old doesn't, I'd appreciate it.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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