ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   handling data in arrays? getting a bit knotted (https://www.excelbanter.com/excel-programming/293544-handling-data-arrays-getting-bit-knotted.html)

Bobsa

handling data in arrays? getting a bit knotted
 
Hi,

ok I admit I'm not much cop at this so a cry for help....

I've got some data in Excel and got it into an array.. great...
now I want to loop through each entry and check the data... if it
matches certain criteria I need to put it into a separate array which
I will then slap back onto a sheet. The data has four values for each
line eg

lonUK, sheffUK, summer, holiday
mancUK, leedUK, autumn, holiday
parisFR, DubIR, spring, work

so i want to loop through the data checking the first two values, of
each record, if they contain UK or IR as the last two letters I want
to extract them into a separate array which I can then paste onto a
separate worksheet area. thats it but it's sort of got me in a
muddle.

any help apprecited

Bobsa

Tom Ogilvy

handling data in arrays? getting a bit knotted
 
Sub Tester1()
Dim arr, arr2
Dim nRows As Long, nCols As Long
Dim i As Long, j As Long, k As Long
Dim l As Long
arr = Range("A1").CurrentRegion
ReDim arr2(LBound(arr, 2) To UBound(arr, 2), _
LBound(arr, 1) To UBound(arr, 1))
i = LBound(arr2, 2) - 1
For k = LBound(arr, 1) To UBound(arr, 1)
If InStr(arr(k, LBound(arr, 2)), "UK") Or _
InStr(arr(k, LBound(arr, 2) + 1), "UK") Or _
InStr(arr(k, LBound(arr, 2)), "IR") Or _
InStr(arr(k, LBound(arr, 2) + 1), "IR") _
Then
i = i + 1
For l = LBound(arr, 2) To UBound(arr, 2)
arr2(l, i) = arr(k, l)
Next
End If
Next
ReDim Preserve arr2(LBound(arr2, 1) To UBound(arr2, 1), _
LBound(arr, 1) To i)
nRows = UBound(arr2, 1) - LBound(arr2, 1) + 1
nCols = UBound(arr2, 2) - LBound(arr2, 2) + 1
Range("M2").Resize(nCols, nRows) = Application.Transpose(arr2)

End Sub

As written, picks up data around cell A1 and puts the results in column M
and to the right starting in cell M2.

--
Regards,
Tom Ogilvy




"Bobsa" wrote in message
om...
Hi,

ok I admit I'm not much cop at this so a cry for help....

I've got some data in Excel and got it into an array.. great...
now I want to loop through each entry and check the data... if it
matches certain criteria I need to put it into a separate array which
I will then slap back onto a sheet. The data has four values for each
line eg

lonUK, sheffUK, summer, holiday
mancUK, leedUK, autumn, holiday
parisFR, DubIR, spring, work

so i want to loop through the data checking the first two values, of
each record, if they contain UK or IR as the last two letters I want
to extract them into a separate array which I can then paste onto a
separate worksheet area. thats it but it's sort of got me in a
muddle.

any help apprecited

Bobsa





All times are GMT +1. The time now is 07:28 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com