Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
Read and write an array
This is probably pretty simple but I'm new to reading and writing arrays. I
need to use a for next loop to read values from cells A1 through A4 for example. Then i need it to write those values to cells to B1 through B4. I'm sure it's a cake walk, but again, I'm new at some of this stuff. |
#2
Posted to microsoft.public.excel.programming
|
|||
|
|||
Read and write an array
A cake walk? No, but close...
Range("B1:B4").Value = Range("A1:A4").Value -- Jim Cone Portland, Oregon USA "Dave L" wrote in message This is probably pretty simple but I'm new to reading and writing arrays. I need to use a for next loop to read values from cells A1 through A4 for example. Then i need it to write those values to cells to B1 through B4. I'm sure it's a cake walk, but again, I'm new at some of this stuff. |
#3
Posted to microsoft.public.excel.programming
|
|||
|
|||
Read and write an array
Thanks Jim. That works for some of the simpler things I need to do, but I was
hoping to use a loop to grab each cells' value separately and then write it separately. In other words I want to select A1 and read the value into the array, select A2 and read the value into the array, etc. Then I want to move to B1 and write the first value, B2 and write the second, etc. I could explain the whole scope of the project, but there will be way too many variations on the scenario above. I'm really just looking for the basic concept of a for next loop and then I can take it from there. |
#4
Posted to microsoft.public.excel.programming
|
|||
|
|||
Read and write an array
Be careful what you wish for. <g '-- Sub OneByOneWithRanges() Dim rngFirst As Range Dim rngOther As Range Dim N As Long Set rngFirst = Range("A1:A4").Cells Set rngOther = Range("C10:F10").Cells For N = 1 To rngFirst.Count rngOther(N).Value = rngFirst(N).Value Next End Sub '-- Sub OneByOneWithArrayAndRange() Dim vFirst As Variant Dim rngOther As Range Dim N As Long 'A variant containing an array. vFirst = Range("A1:A4").Value Set rngOther = Range("C10:F10").Cells 'Transfer array values to other range For N = 1 To UBound(vFirst) rngOther(N).Value = vFirst(N, 1) Next End Sub '-- Sub UseTwoArrays() Dim vFirst As Variant Dim vOther() As Variant Dim M As Long Dim N As Long Dim i As Long Dim j As Long vFirst = Range("A1:A4").Value i = UBound(vFirst, 1) j = UBound(vFirst, 2) ' Transpose array size - columns to rows and rows to columns. ReDim vOther(1 To j, 1 To i) ' Add values from 1st array to 2nd array ' Note (N, M) vs. (M, N) For M = 1 To i For N = 1 To j vOther(N, M) = vFirst(M, N) Next Next ' Add 2nd array values to range. Range("C10:F10").Value = vOther() End Sub -- Jim Cone Portland, Oregon USA "Dave L" wrote in message Thanks Jim. That works for some of the simpler things I need to do, but I was hoping to use a loop to grab each cells' value separately and then write it separately. In other words I want to select A1 and read the value into the array, select A2 and read the value into the array, etc. Then I want to move to B1 and write the first value, B2 and write the second, etc. I could explain the whole scope of the project, but there will be way too many variations on the scenario above. I'm really just looking for the basic concept of a for next loop and then I can take it from there. |
#5
Posted to microsoft.public.excel.programming
|
|||
|
|||
Read and write an array
Thanks again Jim! I think I can make this work. I have one more question and
I'll try to stop bugging you. I need to ignore empty cells in my range. In other words if I have values in all cells in range A1:A4 except for A3, I need to write cells B1:B3 with the values from A1, A2 and A4. Is that easy or should I just write a clean up script to get rid of blank values after they're written? |
#6
Posted to microsoft.public.excel.programming
|
|||
|
|||
Read and write an array
I can't answer your question as it is difficult to see your script from here.
You can check for blank cells with... If Len(rCell.Value) = 0 Then -or- If IsEmpty(rCell) Then Checking for "blank" array elements depends on the data type of the array. Numeric array elements are 0. Object array elements are "Nothing" String array elements are "" Variant array elements are "Empty" -- Jim Cone "Dave L" wrote in message Thanks again Jim! I think I can make this work. I have one more question and I'll try to stop bugging you. I need to ignore empty cells in my range. In other words if I have values in all cells in range A1:A4 except for A3, I need to write cells B1:B3 with the values from A1, A2 and A4. Is that easy or should I just write a clean up script to get rid of blank values after they're written? |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
Array to read data from one sheet and write to another if it meets criteria | Excel Programming | |||
I have a read only xl file, I need it to be read and write | Excel Discussion (Misc queries) | |||
Read/Write | Excel Programming | |||
How can a file be converted from Read-Only to Read/Write | Excel Discussion (Misc queries) | |||
Who has read/write | Excel Programming |