1 Array, 2 problems

mkvarious

New Member
Joined
Jan 24, 2013
Messages
44
hello all,

I am dealing with two arrays. first one is called aTbl and it part of wider procedure 'For Each ...' checking whether selected items meet various criteria of the items or not. aTbl remembers the row number of correct items (rKom.Row).

Code:
    nTbl = nTbl + 1
    If nTbl = 1 Then
        ReDim aTbl(1 To 1)
        aTbl(nTbl) = rKom.Row
    Else
        ReDim Preserve aTbl(1 To nTbl)
        aTbl(nTbl) = rKom.Row
    End If

for those rows that meet all the criteria so all items from aTbl I want to copy selected columns and for that I bring the second array called bTbl. Columns to copy are noncontiguous.

Code:
For nnTbl = LBound(aTbl) To UBound(aTbl)
    nnbbTbl = nnbbTbl + 1
    If nnbbTbl = 1 Then
        ReDim bTbl(1 To 1)
        
        bTbl(nnbbTbl) = Union(Range(Cells(aTbl(nnTbl), sPoczątek), Cells(aTbl(nnTbl), sPodstawowy)), _
        Range(Cells(aTbl(nnTbl), sPierwszyKolejny), Cells(aTbl(nnTbl), sDrugiKolejny)))
    Else
        ReDim Preserve bTbl(1 To nnbbTbl)
        
        bTbl(nnbbTbl) = Union(Range(Cells(aTbl(nnTbl), sPoczątek), Cells(aTbl(nnTbl), sPodstawowy)), _
        Range(Cells(aTbl(nnTbl), sPierwszyKolejny), Cells(aTbl(nnTbl), sDrugiKolejny)))
    End If
Next nnTbl

variables: sPoczątek, sPodstawowy, sPierwszyKolejny, sDrugiKolejny are strings setup as column (letters).

when I select my noncontiguous data for each aTbl(nnTbl) item with Union and Select then the result is fine.
Code:
Union(Range(Cells(aTbl(nnTbl), sPoczątek)), Range(Cells(aTbl(nnTbl), sPodstawowy)),Range(Cells(aTbl(nnTbl), sPierwszyKolejny)), Range(Cells(aTbl(nnTbl), sDrugiKolejny))).Select
see three consecutive rows selected, here:
https://docs.google.com/file/d/0B3TkcO-UmuQAZTJ4LS1lWFhqWW8/edit?usp=sharing
https://docs.google.com/file/d/0B3TkcO-UmuQAQTB1SDFrTzYza0E/edit?usp=sharing
https://docs.google.com/file/d/0B3TkcO-UmuQAUjhxbFI0WDNSR1E/edit?usp=sharing

but when it is added to bTbl the result is incorrect. the line below is supposed to paste bTbl data but when I try to paste it then I only get 'N/A' results. any ideas, why?
Code:
[a2].Resize(UBound(bTbl), UBound(Application.Transpose(bTbl))) = bTbl

I know this line is fine as I have tried that on another array with numeric array and then it copied data into another range, fine. though I tried that only on contiguous array...
does it matter?

I have done a check and added bTbl array into a name 'drugaTablica' in a NameManager
Code:
Names.Add Name:="drugaTablica", RefersTo:=bTbl
it proved that only contiguous array was copied and noncontiguous array was not! first row stops at "WG39734" and then it breaks to the next line and value "GB" whereas it should have been: "BC/BOGOF".
see the results, here:
https://docs.google.com/file/d/0B3TkcO-UmuQARVZxMnAxd3ZMcDA/edit?usp=sharing

so the first problem with bTbl is: although it selects all noncontiguous cells/arrays with the line below when the same

the second problem is probably connected to the fact bTbl array does not get copied properly and then when I try to paste it with then it does not paste the results.
Code:
[a2].Resize(UBound(bTbl), UBound(Application.Transpose(bTbl))) = bTbl

any help is much appreciated.

I picked the array pattern to my project as I have believed it was more flexible then simple range creation but with time I get more and more issues with it and this discourages me lot!
though it is too late to amend and redo from the stratch, now.

please help as otherwise I will have to add noncontiguous cells/arrays to a black sheet row by row in a loop, then creating a range with all rows/results which is total lost of the array idea, as I get it!

desperate for help,
mkvarious
 

Excel Facts

Pivot Table Drill Down
Double-click any number in a pivot table to create a new report showing all detail rows that make up that number

Forum statistics

Threads
1,223,632
Messages
6,173,472
Members
452,516
Latest member
archcalx

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top