View Single Post
  #6   Report Post  
Posted to microsoft.public.excel.programming
[email protected] benmcclave@gmail.com is offline
external usenet poster
 
Posts: 29
Default Another question

suppose column headings of that three are suppliername, contact, and

emailid. And if i dont know the column no. In that case?


Try:

Sub FindandCopy()
Dim x As Long
Dim sFind(1 To 3) As String
Dim sFound As String

'Update values below as necessary
sFind(1) = "suppliername"
sFind(2) = "contact"
sFind(3) = "emailid"

On Error Resume Next
For x = 1 To 3
'Change "Rows("1:1")" to whatever range includes your column headings
sFound = sFound & Rows("1:1").Find(What:=sFind(x), After:=Cells(1, 1), LookIn:= _
xlFormulas, LookAt:=xlWhole, SearchOrder:=xlByRows, SearchDirection:= _
xlNext, MatchCase:=False, SearchFormat:=False).EntireColumn.Address & ","
Next x
On Error GoTo 0

If Len(sFound) 1 Then
sFound = Left(sFound, Len(sFound) - 1)
Sheets("Sheet1").Range(sFound).Copy _
Sheets("Sheet2").Range("A1")
End If
End Sub