Data Extraction from an Array

brmeeke

New Member
Joined
Jan 30, 2008
Messages
21
Hi

I need to extract data from a series of columns to build a new array. Please look at the table below:

ABCDEF
Error NumRow KeyMessageError NumRow KeyMessage
00990099
00990099
12.07.1130099
00990099
009942.09.416
00990099
00990099
22.12.2130099
00990099
32.14.3130099

<tbody>
</tbody>

Column A & D have an ascending error number. I need to find the non-zero rows from Column A & D and then pick up the data that is in the next two columns. The objective is to create a new array that looks like this:

12.07.113
22.12.213
32.14.313
42.09.416

<tbody>
</tbody>

My first thought was to capture the Address of the row and column that holds the error number, and then use Offsets to extract the information from the other two rows. I hoped that I could use the Match function in an Array formula and present columns A & D as one continuous array but I could not figure out a syntax that Match would accept.

Does anyone have any suggestions?


Thank you
Brian
 

Excel Facts

Add Bullets to Range
Select range. Press Ctrl+1. On Number tab, choose Custom. Type Alt+7 then space then @ sign (using 7 on numeric keypad)
Sure, why not loop thru columns A and D and where only those whose value is greater than 0 (zero) , use the Offset(, 2).value to get row.key values...
 
Last edited:
Upvote 0
Currently, this is what I have; still need to get it all in 1 column in order though

Code:
Option Explicit

Sub x1085137()
'https://www.mrexcel.com/forum/excel-questions/1085137-data-extraction-array.html
Dim LRow As Long, r As Integer, c As Integer


Cells.Copy
Sheets.Add after:=ActiveSheet
ActiveSheet.Paste


LRow = Cells(Rows.Count, "A").End(xlUp).Row


For c = 1 To 4 Step 3
    For r = LRow To 2 Step -1
        If Cells(r, c).Value = 0 Then
            Range(Cells(r, c), Cells(r, c + 2)).Delete (xlUp)
        End If
    Next r
Next c


End Sub
 
Upvote 0
Now with sorting

Code:
Option Explicit

Sub x1085137()
'https://www.mrexcel.com/forum/excel-questions/1085137-data-extraction-array.html
Dim LRow As Long, LRow2 As Long, r As Integer, c As Integer


Application.ScreenUpdating = False


Cells.Copy
Sheets.Add after:=ActiveSheet
ActiveSheet.Paste


LRow = Cells(Rows.Count, "A").End(xlUp).Row


For c = 1 To 4 Step 3
    For r = LRow To 2 Step -1
        If Cells(r, c).Value = 0 Then
            Range(Cells(r, c), Cells(r, c + 2)).Delete (xlUp)
        End If
    Next r
Next c


LRow = Cells(Rows.Count, "D").End(xlUp).Row
LRow2 = Cells(Rows.Count, "A").End(xlUp).Row + 1


Range(Cells(2, 4), Cells(LRow, 6)).Cut Cells(LRow2, 1)


Range("A2", Range("A2").End(xlDown)).Sort Key1:=Range("A2"), Order1:=xlAscending, Header:=xlNo


Range("D1:F1").ClearContents
Range("A1").Select
Application.ScreenUpdating = True
End Sub
 
Upvote 0
Hi,

Does this get you any closer to where you need to be...

Code:
Sub test()


    Dim arr1, arr2, cmp
    Dim lRow As Long, a As Long, b As Long, ct As Long
    
    lRow = Cells(Rows.Count, 1).End(xlUp).Row
    ct = 1
    arr1 = Range("A2:C" & lRow)
    arr2 = Range("D2:F" & lRow)
    ReDim cmp(1 To lRow, 1 To 3)
    
    For a = LBound(arr1) To UBound(arr1)
        If Not (arr1(a, 1)) = 0 Then
            cmp(ct, 1) = arr1(a, 1)
            cmp(ct, 2) = arr1(a, 2)
            cmp(ct, 3) = arr1(a, 3)
            ct = ct + 1
        End If
    Next
    For b = LBound(arr2) To UBound(arr2)
        If Not (arr2(b, 1)) = 0 Then
            cmp(ct, 1) = arr2(b, 1)
            cmp(ct, 2) = arr2(b, 2)
            cmp(ct, 3) = arr2(b, 3)
            ct = ct + 1
        End If
    Next
    Range("I2").Resize(ct - 1, 3) = cmp
    
End Sub
 
Upvote 0
Thank you for your replies. I agree that with a bit of VBA code, I could loop through the cells and perform the necessary steps. However, my spreadsheet does not have any VBA code today and I was hoping that I could generate the desired result without having to go that route. (Sorry if I am being too simplistic)

As far as the sorting issue is concerned, I should have noted that I do not care. I am going to take the extracted array and re-sort it a couple of different ways before I show the results to the end-user. I just need to figure out a way to extract the non-zero error rows first.

Again - appreciate your help.


Brian
 
Upvote 0
With formulas it could be like this:


ABCDEFGHIJKL
1Error numRow keyMessageError numRow keyMessageReferArray FormulaError numRow keyMessage
2009900990$A$412.07.113
3009900990$A$922.12.213
412.07.1130099$A$4$A$1132.14.313
5009900990$D$642.09.416
6009942.09.4160
7009900990
8009900990
922.12.2130099$A$9
10009900990
1132.14.3130099$A$11
120
130
140
150
16$D$6
170
180
190
200
210

<tbody>
</tbody>

Formulas
CellFormula
H2=IF(A2=0,0,ADDRESS(ROW(A2),COLUMN(A2)))
...Copy to H11
H12=IF(D2=0,0,ADDRESS(ROW(D2),COLUMN(D2)))
Copy to H21
Array Formula
I2{=IFERROR(INDEX($H$1:$H$21,SMALL(IF($H$2:$H$21>0,ROW()),ROW()-1)),"")}
Formula
J2=IFERROR(INDIRECT(I2),"")
K2=IFERROR(OFFSET(INDIRECT(I2),0,1),"")
L2=IFERROR(OFFSET(INDIRECT(I2),0,2),"")
Copy to row 21

<tbody>
</tbody>

<tbody>
</tbody>
 
Upvote 0
If you are going to use a single column then


ABCDEFG
1Error numRow keyMessageError numRow keyMessage
2009912.07.113
3009922.12.213
412.07.11332.14.313
5009942.09.416
60099
70099
80099
922.12.213
100099
1132.14.313
120099
130099
140099
150099
1642.09.416
170099
180099
190099
200099
210099

<tbody>
</tbody>

Formulas
CellArray Formula
E2{=IFERROR(INDEX(A$1:A$21,SMALL(IF($A$2:$A$21>0,ROW()),ROW()-1)),"")}
F2{=IFERROR(INDEX(B$1:B$21,SMALL(IF($A$2:$A$21>0,ROW()),ROW()-1)),"")}
G2{=IFERROR(INDEX(C$1:C$21,SMALL(IF($A$2:$A$21>0,ROW()),ROW()-1)),"")}

<tbody>
</tbody>
Copy to row 21, To accept press Shift + Control + Enter

<tbody>
</tbody>


---
Just in case, I put the macro

Code:
Sub arreglo()
    i = 2
    For Each d In Range("A2:A11, D2:D11")
        If d.Value > 0 Then Cells(i, "H").Resize(1, 3).Value = d.Resize(1, 3).Value: i = i + 1
    Next
End Sub
 
Upvote 0
thanks for the suggestion of the single column. I already thought about that and it is an option however the array is quite large so the number of rows required to work with this data as a single column would be quite significant.
 
Upvote 0
@DanteAmor

Nice!!

Just in case, I put the macro

Code:
Sub arreglo()
    i = 2
    For Each d In Range("A2:A11, D2:D11")
        If d.Value > 0 Then Cells(i, "H").Resize(1, 3).Value = d.Resize(1, 3).Value: i = i + 1
    Next
End Sub
 
Last edited:
Upvote 0

Forum statistics

Threads
1,216,022
Messages
6,128,324
Members
449,440
Latest member
Gillian McGovern

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