+ Reply to Thread
Results 1 to 6 of 6

Will using vba macro LEN() fail if cell is empty?

  1. #1
    Registered User
    Join Date
    11-21-2012
    Location
    tallahassee
    MS-Off Ver
    Excel 2007
    Posts
    10

    Will using vba macro LEN() fail if cell is empty?

    Hello,

    I am looping through the rows of data for a column. I am trying to check to see if the cell has data. If it does, I format it to 0.00, else I do nothing. However, when the code encounters a cell that doesnt have data the execution of the code stops. No error or anything. Just stops. Here is the code I am using...
    Please Login or Register  to view this content.
    Is there anything wrong with this that anyone can tell? Any advice greatly appreciated.

    Thanks
    Last edited by JosephP; 11-29-2012 at 04:42 PM. Reason: add code tags

  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
    44,464

    Re: Will using vba macro LEN() fail if cell is empty?

    I'd like to see a sample workbook that exhibits the problem. How does the array get populated? What's in it in general, and what's in the element when it fails? As it's meant to be a column number, if it is zero the code will fail.


    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
    Registered User
    Join Date
    11-21-2012
    Location
    tallahassee
    MS-Off Ver
    Excel 2007
    Posts
    10

    Re: Will using vba macro LEN() fail if cell is empty?

    Thanks for the reply! The array gets populated with the code below. I have checked the array and it does have the values I need in it.

    Something I just noticed is that if I use actual numbers in the ".cells(4,4) part from the code in my first post, it seems to work but when I use variables it doesnt. I have done a msgbox right before the IF statement to check to make sure that the variables have the correct values and they do. Just for giggles I created two dummy variables and gave them a value of like 8 and 10 and tried using those in the expression and they too failed. When used in ANY statement such as IF, msgbox etc.... the page stops. I am new to vba macro coding so this is new to me... I also tried ISEMPTY() with the same results.

    The code just places row numbers into the array.
    Please Login or Register  to view this content.
    PS: I can send you an example if you tell me how to do so using this website.

    thanks!
    Last edited by JosephP; 11-29-2012 at 04:43 PM. Reason: please learn to use code tags!

  4. #4
    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
    44,464

    Re: Will using vba macro LEN() fail if cell is empty?

    To Attach a File:

    1. Click on Go Advanced
    2. In the frame Attach Files you will see the button Manage Attachments
    3. Click the button.
    4. A new window will open titled Manage Attachments - Excel Forum.
    5. Click the Browse... button to locate your file for uploading.
    6. This will open a new window File Upload.
    7. Once you have located the file to upload click the Open button. This window will close.
    8. You are now back in the Manage Attachments - Excel Forum window.
    9. Click the Upload button and wait until the file has uploaded.
    10. Close the window and then click Submit.

  5. #5
    Registered User
    Join Date
    11-21-2012
    Location
    tallahassee
    MS-Off Ver
    Excel 2007
    Posts
    10

    Re: Will using vba macro LEN() fail if cell is empty?

    Thanks for the information on uploading a file. I think I may have found out why the variables wont work the way they were set up. The array is a string array(containing numbers). When I put a cint(arrayName(xx)) around it, it worked. Guess it must be a variable of type integer to be used in that context. Wish it would have given me some indication of the problem instead of just stopping execution....

    thank you for the information.

  6. #6
    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
    44,464

    Re: Will using vba macro LEN() fail if cell is empty?

    You're welcome. Looks like you did most of the work yourself


    If you experience this sort of issue in the future, you can always try and check the cell address in the Immediate window. As yo step through the code, type:

    ?.Cells(xxx, arFTELine(xx)).Address

    If one of the variables isn't valid, the print will probably complain ...


    Regards, TMS

+ 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