+ Reply to Thread
Results 1 to 3 of 3

Cell extraction producing phantom space

Hybrid View

  1. #1
    Registered User
    Join Date
    12-17-2010
    Location
    Missouri, USA
    MS-Off Ver
    Excel 2007
    Posts
    2

    Cell extraction producing phantom space

    Hello forum dwellers,

    I have a workbook to produce which has many sheets in it. I have created code to compare the value of the first cell in a specific sheet to a value from a table which I have written to a variable. However, when using the immediate window, I see that pulling the value from the cell adds a space at the beginning. The comparison then evaluates improperly (which I believe is linked to the phantom space).

    If x < Cells(1, 1) Then GoTo Line1
    If x > Cells(1, 1) Then GoTo Line2
    If x = Cells(1, 1) Then GoTo Line3
    The value in cell A1 of the active sheet is 1301853. The immediate window shows x = 130303 (correct), but
    Cells(1,1) = " 1301853" (quotes not present, but illustrating space). However, the actual cell does not contain that leading space.

    When stepping through the macro, the first If statement comes back false, and the second true, even though 130,303 < 1,301,853, and I can only think it is due to the phantom space that the Cells(1,1) call seems to be adding. Help please .
    Last edited by Mairsil; 12-17-2010 at 07:19 PM.

  2. #2
    Forum Guru
    Join Date
    03-02-2006
    Location
    Los Angeles, Ca
    MS-Off Ver
    WinXP/MSO2007;Win10/MSO2016
    Posts
    12,960

    Re: Cell extraction producing phantom space

    1. You did not specify how your variable "x" is declared, i.e., whether is is as INTEGER, LONG, etc.
    2. Look up the TRIM function.
    3. Look up the SELECT CASE statement to avoid the If/Goto's
    Ben Van Johnson

  3. #3
    Registered User
    Join Date
    12-17-2010
    Location
    Missouri, USA
    MS-Off Ver
    Excel 2007
    Posts
    2

    Re: Cell extraction producing phantom space

    Thanks, figured it was something simple that I just wasn't seeing. It was a type mismatch.

+ 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