Consulting

Results 1 to 6 of 6

Thread: Copying values

  1. #1
    VBAX Regular
    Joined
    Jul 2008
    Posts
    47
    Location

    Copying values

    Hello,

    Using the code below i am copying values from two worksheets into one.

    Private Sub CopyData(path1, path2)
    
    Set wb1 = Workbooks.Open(path1, True, True)
    Set wb2 = Workbooks.Open(path2, True, True)
    
    With ThisWorkbook.Worksheets("Sheet1")
            .Columns("A:B").Value = wb1.Worksheets(sheetName(TextBox1)).Columns("A:B").Value
            .Columns("D:E").Value = wb2.Worksheets(sheetName(TextBox2)).Columns("A:B").Value
    End With
    
    End Sub
    The problem i am having is when i copy over any values with 'E's in it is copying them as exponentials rather than just E's. For example:

    5697E93
    will copy as:

    5.70E+96
    Anyone got any ideas?

    Ive tried using .formula and .text instead of .value.
    .formula copied the same
    .text copied no values

    Any fixes need to be coded, as i do not create the spreadsheets, this is the format they are given to me.

    I am using Microsoft Office XP (2002) Excel spreadsheets

    Hope you can help
    Gary

  2. #2
    VBAX Mentor
    Joined
    Oct 2007
    Posts
    372
    Location
    can you do just change formatcells for all cells to text?

  3. #3
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    Is this approach acceptable?

    [vba]

    Range("B1").Value = IIf(TypeName(Range("A1").Value) = "String", "'", "") & Range("A1").Value
    [/vba]
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  4. #4
    VBAX Regular
    Joined
    Jul 2008
    Posts
    47
    Location
    Quote Originally Posted by grichey
    can you do just change formatcells for all cells to text?
    I've tried this, when i select general it leaves it in the second format, when i select number it turns it into a huge number because it is picking up the E as exponential.

  5. #5
    VBAX Regular
    Joined
    Jul 2008
    Posts
    47
    Location
    Quote Originally Posted by xld
    Is this approach acceptable?

    [vba]

    Range("B1").Value = IIf(TypeName(Range("A1").Value) = "String", "'", "") & Range("A1").Value
    [/vba]
    Hi thanks for the quick reply.

    Sorry, i dont fully understand what that code does, does it only copy values that are stored as string?

    And doing it like that would i have to copy each individual record one by one?

    Thanks for your help

  6. #6
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    Not, it precedes a string value with an apostophe, stopping Excel converting to an number.
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

Posting Permissions

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