View Single Post
  #5   Report Post  
Posted to microsoft.public.excel.programming
Claus Busch Claus Busch is offline
external usenet poster
 
Posts: 3,872
Default Find string from column A in Range("B2:F7") list the header of that column/s

Hi Howard,

Am Mon, 12 Aug 2013 01:22:52 -0700 (PDT) schrieb Howard:

The order of listing in Col J is confusing. Does the code look the column A items staeting from the bottom to the top?


the code looks from A2 to the bottom. For the search in B2:F7 you can
fix the searchorder with
Searchorder:=xlByRows or Searchorder:=xlByColumns
Or you look in column A for the strings in B2:F7:

Sub ListHeader3()
Dim lngLstRow As Long
Dim rngA As Range
Dim c As Range
Dim firstaddress As String
Dim i As Long

i = 1
With Sheets("Sheet2")
lngLstRow = .UsedRange.Rows.Count
For Each rngA In .Range("B2:F7")
Set c = .Range("A2:A" & lngLstRow).Find(rngA, _
LookIn:=xlValues, after:=.Range("A" & lngLstRow))
If Not c Is Nothing Then
firstaddress = c.Address
Do
.Cells(i, "J") = .Cells(1, rngA.Column)
.Cells(i, "K") = rngA.Address
i = i + 1
Set c = .Range("A2:A" & lngLstRow).FindNext(c)
Loop While Not c Is Nothing And c.Address < firstaddress
End If
Next
lngLstRow = .Cells(Rows.Count, "J").End(xlUp).Row
.Range("J1:K" & lngLstRow).RemoveDuplicates _
Columns:=Array(1, 2), Header:=xlNo
End With
End Sub


Regards
Claus B.
--
Win XP PRof SP2 / Vista Ultimate SP2
Office 2003 SP2 /2007 Ultimate SP2