LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #25   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,514
Default List found strings on sheet

Garry, Id like to try you last suggestion, but am lost as to what or
how that named range should look like.


This v5 uses a comma delimited list stored in a cell named "IdList" on
"Instructions". It creates an array of arrays for all IDs listed on the
'tagged' sheets, then converts that to a 1-based 2D array to 'dump'
into "Instructions" on the next empty row.

Note that any all-numeric IDs return as numeric data (not as text) and
so requires formatting ColA if you want the results for numeric IDs
displayed as text. Complete code follows..



Sub FindSheetsWithID_v5()
' Looks for an ID on all sheets with search tag,
' and outputs results to summary sheet named "Instructions".
' Note: The search tag is a local scope defined name range
' that contains the search data column address.

Dim Wks As Worksheet, wksTarget As Worksheet, rng As Range
Dim sID$, sOut$, sAddr1$, lCount&, n&, vData

Const sRngToSearch$ = "MyTag" '//edit to suit

Set wksTarget = ThisWorkbook.Sheets("Instructions")
'Assume comma delimited ID list stored in named range
With wksTarget
.Activate: sID = .Range("IdList").Text
End With
If Trim(sID) = "" Then Exit Sub

On Error GoTo Cleanup
vData = Split(sID, ","): ReDim vDataOut(UBound(vData))
For n = LBound(vData) To UBound(vData)
sOut = vData(n): sID = sOut
For Each Wks In ThisWorkbook.Worksheets
If bNameExists(sRngToSearch, Wks) Then
sOut = sOut & "," & Wks.Name & "=": sAddr1 = ""
With Wks.Range(sRngToSearch)
Set rng = .Find(What:=sID, LookIn:=xlValues, _
LookAt:=xlWhole, SearchOrder:=xlByColumns)
If Not rng Is Nothing Then
sAddr1 = rng.Address
Do
lCount = lCount + 1: Set rng = .FindNext(rng)
Loop While Not rng Is Nothing And rng.Address < sAddr1
End If 'Not rng Is Nothing
End With 'Wks.Range(sRngToSearch)
sOut = sOut & lCount: lCount = 0
End If 'bNameExists
Next 'Wks
vDataOut(n) = Split(sOut, ",")
Next 'n

'Output to worksheet
Xform_1DimArrayOfArraysTo2D vDataOut
With wksTarget.Cells(Rows.Count, "A").End(xlUp)(2)
.Resize(UBound(vDataOut), UBound(vDataOut, 2)) = vDataOut
.EntireColumn.NumberFormat = "@"
End With


Cleanup:
Set wksTarget = Nothing: Set rng = Nothing
End Sub

Function bNameExists(sName$, oSource) As Boolean
' Checks if sName exists in oSource
' Arguments:
' sName The defined name to check for
' oSource A ref to the Wkb or Wks being checked
' Returns:
' True if name exists

Dim x As Object
On Error Resume Next
Set x = oSource.Names(sName): bNameExists = (Err = 0)
End Function

Sub Xform_1DimArrayOfArraysTo2D(Arr())
' Restructures a 1D 0-based dynamic array of arrays to a fixed 2D
1-based array
' Arguments:
' Arr() The array of arrays to be converted
'
Dim v1, vTmp(), lMaxCols&, lMaxRows&, n&, k&

If VarType(Arr) < vbArray Then Exit Sub

lMaxRows = UBound(Arr) + 1: vTmp = Arr: Erase Arr
'Get size of Dim2
For n = LBound(vTmp) To UBound(vTmp)
k = UBound(vTmp(n))
lMaxCols = IIf(k + 1 lMaxCols, k + 1, lMaxCols)
Next 'n

ReDim Arr(1 To lMaxRows, 1 To lMaxCols)
For n = LBound(vTmp) To UBound(vTmp)
For k = LBound(vTmp(n)) To UBound(vTmp(n))
Arr(n + 1, k + 1) = vTmp(n)(k)
Next 'k
Next 'n
End Sub

--
Garry

Free usenet access at http://www.eternal-september.org
Classic VB Users Regroup!
comp.lang.basic.visual.misc
microsoft.public.vb.general.discussion




 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Search for values in a sheet and copy found records one after theother in another sheet AndreasHermle Excel Programming 12 June 17th 11 08:12 PM
Reducing a List by Eliminating Entries in it Found in Another List Ralph Excel Programming 7 September 30th 09 05:21 PM
Excell Dropdown List. Display alternate text than found in list. Shawnn Excel Discussion (Misc queries) 14 December 11th 08 07:43 PM
I found these text strings printed out. What would they do if used in VBA? Enda Excel Programming 2 November 23rd 06 03:41 PM
How to find number of pairs of strings from list of strings? greg_overholt Excel Worksheet Functions 5 January 27th 06 10:42 PM


All times are GMT +1. The time now is 11:42 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"