+ Reply to Thread
Results 1 to 3 of 3

Variant array changes numbers stored as text

  1. #1
    Registered User
    Join Date
    03-06-2013
    Location
    United States
    MS-Off Ver
    Excel Windows 8
    Posts
    2

    Variant array changes numbers stored as text

    Hello!

    So I have this macro I made for work... its too irrelevant to explain the entire macro, so I will try to explain the part I have an issue with. A section of the macro copies values from a named range (Ex. "Color1") into an array that holds values temporarily from loop to loop (Ex. "ColorVT") and then that is copied into a final array (Ex. "FinalVT_Color") that is pasted into a column in a final output sheet once the macro runs through a bunch of loops to populate this "FinalVT_Color". My problem is that if I have a color number that was entered as '002 in excel (# as text so the first 0 doesnt fall off) within the named range "Color1" ... by the time the macro prints the "FinalVT_Color" color array it has changed to 2. That is a huge issue for me, what to do? Please help!!!! Thank you

    Dim Colors As Integer
    Dim ColorVT As Variant
    Dim IdentifierVT As Variant
    Dim BusinessUnitVT As Variant
    Dim WarehouseVT As Variant

    Dim ColorNumString As String
    Dim IdentifierNumString As String
    Dim BusinessUnitNumString As String
    Dim WarehouseNumString As String

    Dim k As Integer
    Dim FinalVT_ArrayPosition As Long
    Dim FinalVT_Color()
    Dim FinalVT_Identifier()
    Dim FinalVT_BusinessUnit()
    Dim FinalVT_Warehouse()



    For k = 1 To WeeksPerMonth '-------------------------------------------- LOOPS THROUGH EACH WEEK IN MONTH

    ColorNumString = "Color" & CStr(i) '----------------------------------- "i" RANGES B/W 1 AND 10, OUTSIDE LOOP
    Set ColorVT = WorkingPlan.Names(ColorNumString).RefersToRange
    ReDim Preserve FinalVT_Color(FinalVT_ArrayPosition) '---------------------- "FinalVT_ArrayPosition" INTIALLY = 1
    FinalVT_Color(FinalVT_ArrayPosition) = ColorVT(Colors) '---------- "Colors" RANGES B/W 1 AND 10, OUTSIDE LOOP

    IdentifierNumString = "Identifier" & CStr(i)
    Set IdentifierVT = WorkingPlan.Names(IdentifierNumString).RefersToRange
    ReDim Preserve FinalVT_Identifier(FinalVT_ArrayPosition)
    FinalVT_Identifier(FinalVT_ArrayPosition) = IdentifierVT(Colors)

    BusinessUnitNumString = "BusinessUnit" & CStr(i)
    Set BusinessUnitVT = WorkingPlan.Names(BusinessUnitNumString).RefersToRange
    ReDim Preserve FinalVT_BusinessUnit(FinalVT_ArrayPosition)
    FinalVT_BusinessUnit(FinalVT_ArrayPosition) = BusinessUnitVT(Colors)

    WarehouseNumString = "Warehouse" & CStr(i)
    Set WarehouseVT = WorkingPlan.Names(WarehouseNumString).RefersToRange
    ReDim Preserve FinalVT_Warehouse(FinalVT_ArrayPosition)
    FinalVT_Warehouse(FinalVT_ArrayPosition) = WarehouseVT(Colors)

    FinalVT_ArrayPosition = FinalVT_ArrayPosition + 1

    Next

    .
    .
    .
    .
    .

    WorkingPlan.Sheets("Vertical Table").Range("D2:D" & UBound(FinalVT_Color) + 1) _
    = WorksheetFunction.Transpose(FinalVT_Color)

    WorkingPlan.Sheets("Vertical Table").Range("E2:E" & UBound(FinalVT_Identifier) + 1) _
    = WorksheetFunction.Transpose(FinalVT_Identifier)

    WorkingPlan.Sheets("Vertical Table").Range("A2:A" & UBound(FinalVT_BusinessUnit) + 1) _
    = WorksheetFunction.Transpose(FinalVT_BusinessUnit)

    WorkingPlan.Sheets("Vertical Table").Range("F2:F" & UBound(FinalVT_Warehouse) + 1) _
    = WorksheetFunction.Transpose(FinalVT_Warehouse)

  2. #2
    Forum Expert
    Join Date
    11-29-2010
    Location
    Ukraine
    MS-Off Ver
    Excel 2019
    Posts
    4,168

    Re: Variant array changes numbers stored as text

    hi bumbochaka, welcome to Excelforum, please check attachment, press Run button. I think the idea to overcome your issue is clear
    Attached Files Attached Files

  3. #3
    Registered User
    Join Date
    03-06-2013
    Location
    United States
    MS-Off Ver
    Excel Windows 8
    Posts
    2

    Re: Variant array changes numbers stored as text

    Thank you very much for taking the time to post this solution! Worked perfectly

+ 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. [SOLVED] Convert all numbers stored as text or custom formatted to numbers &no decimals - 40 sheets
    By synses in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 06-19-2013, 01:46 AM
  2. [SOLVED] How do you apply the int() in VBA in order to convert numbers stored as text to numbers
    By djaurit in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 12-21-2012, 02:57 PM
  3. Solved! Using VLOOKUP when array has both numbers and numbers stored as text
    By Kari Gulbrandsen in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 08-24-2012, 01:58 PM
  4. VLOOKUP should compare numbers stored as text to plain numbers.
    By VLOOKUP - Numbers stored as text in forum Excel Formulas & Functions
    Replies: 0
    Last Post: 03-31-2006, 12:55 PM
  5. Convert numbers stored as text to numbers Excel 2000
    By Darlene in forum Excel General
    Replies: 6
    Last Post: 01-31-2006, 04:10 PM

Tags for this Thread

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