Thread: Array Coding
View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Patrick Molloy[_2_] Patrick Molloy[_2_] is offline
external usenet poster
 
Posts: 1,298
Default Array Coding

this assumes you have a table in a sheet named "main"
The table starts in A1 with WM7886 with A13 having WM1349 and C13 having 1712

The looks at each sheet in turn, skipping over 'main'
the for each of the items, we do a simple match() to see if the WM* code is
present and if it is, copy over the data

NOTE: this is not optimised in any way...but for smallish applications lie
this, it snot a particularly lengthy process.

My workbook is available

Option Explicit
Sub PopData()
Dim source As Range
Dim ws As Worksheet
Dim cell As Range
Dim index As Long
For Each ws In Worksheets
If ws.Name < "main" Then
For Each cell In Range(Range("A1"), Range("A1").End(xlDown))
index = matched(cell.Value, ws)
If index 0 Then
ws.Cells(index, 200).End(xlToLeft).Offset(0, 1) =
cell.Offset(, 1)
ws.Cells(index, 200).End(xlToLeft).Offset(0, 1) =
cell.Offset(, 2)
End If
Next 'item
End If
Next 'sheet
End Sub
Function matched(item As String, ws As Worksheet) As Long
On Error Resume Next
matched = WorksheetFunction.Match(item, ws.Columns(1), False)
On Error GoTo 0
End Function

note that some worksheet functions like Match() and Vlookup() actually raise
errors in VBA. So by "wrapping" them in a safe function, we can avoid
horrible code issues later when it comes to debugging longer and more complex
code





"Hazel" wrote:

I receive the following information as an attachment to an Email. The
attachment opens in Notepad.

4100,WM7886,255,1404
4100,WM5589,255,1473
4100,WM6458,253,1230
4100,WM6467,254,966
4100,WM13163,255,1371
4100,WM4241,255,1371
4100,WM10256,255,1323
4100,WM1696,255,1578
4100,WM1695,255,1467
4100,WM6909,255,1435
4100,WM6332,255,993
4100,WM2899,255,1018
4100,WM1349,243,1712
Always ignore the 1st part of the array e.g.4100, this is the code of the
site. The 2nd part of the array is always in column "A" and it could be on
any row within 25 sheets all with different Tab Names. The maximum number of
rows used on each sheet is 35. The final 2 parts of the array need to enter
the 1st and 2nd empty columns on the row that is selected by the 2nd part of
the array is it possible to code into Excel. At the moment I am doing Text to
Columns then cut and pasting after finding the correct row in column "A" that
matches the second part of the array. I hope I have explained the above
properly -- I am using XP Office.

--
Many thanks

hazel