Results 1 to 3 of 3

Thread: Assign array value to cell?

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Jun 2009
    Posts
    19

    Assign array value to cell?

    I think I'm missing something simple - so please help if you can. I want to create an array from one sheet and then take specific elements from that array and assign them to the appropriate cells in another worksheet. So far, I can grab the values fine, assign them to an array ok and activate the right sheet. What doesn't happen is that the specific array values aren't being copied correctly to the new sheet. When I run the code, everything seems to work ok but I don't get any values into the right cells. The line in red is where I'm running into troubles. Here is what I have so far:

    Code:
    Dim update_values() As Double
    
    Set xl_working_sheet2 = xlNew.Worksheets("KPI")
        xl_working_sheet2.Activate
        
        ' dimension the dynamic array
        ReDim update_values(10)
        
        ' Get the values from the KPI sheet and assign them to an array
        update_values(1) = xl_working_sheet2.Cells(14, 3).Value
            
        Set xl_working_sheet = xlNew.Worksheets("Working Plan")
        xl_working_sheet.Activate
        
       ' MsgBox (position2)
        'MsgBox (update_values(6))
        
        xl_working_sheet.Cells(4, 15) = update_values(6)

  2. #2

    Thread Starter
    Junior Member
    Join Date
    Jun 2009
    Posts
    19

    Re: Assign array value to cell?

    Ok.. so the code works if I use the range method instead with a specific entry like this:

    Code:
    xl_working_sheet.range("D15") = update_values(6)
    Is there any way to specify a numeric cell value??

  3. #3
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: Assign array value to cell?

    xl_working_sheet.Cells(4, 15) = update_values(6)
    is actually O4
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

Posting Permissions

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



Click Here to Expand Forum to Full Width