Home |
Search |
Today's Posts |
#3
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Many thanks - I'll give it a try.
"Jan Karel Pieterse" wrote: Hi Cdb, I am trying to write a macro that will search across several sheets unsing the find function, and then if it finds the right thing, to concatenate that with the 2 columns before it. You are using sendkeys, which is hardly ever needed and very error prone. Here is some code I wrote a few years back that does the finding work: Sub FindItAll() Dim oSheet As Object Dim Firstcell As Range Dim NextCell As Range Dim WhatToFind As Variant WhatToFind = Application.InputBox("What are you looking for ?", "Search", , 100, 100, , , 2) If WhatToFind < "" And Not WhatToFind = False Then For Each oSheet In ActiveWorkbook.Worksheets oSheet.Activate oSheet.[a1].Activate Set Firstcell = Cells.Find(What:=WhatToFind, LookIn:=xlValues, LookAt _ :=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:=False) If Not Firstcell Is Nothing Then Firstcell.Activate MsgBox ("Found " & Chr(34) & WhatToFind & Chr(34) & " in " & oSheet.Name & "!" & Firstcell.Address) On Error Resume Next While (Not NextCell Is Nothing) And (Not NextCell.Address = Firstcell.Address) Set NextCell = Cells.FindNext(After:=ActiveCell) If Not NextCell.Address = Firstcell.Address Then NextCell.Activate MsgBox ("Found " & Chr(34) & WhatToFind & Chr(34) & " in " & oSheet.Name & "!" & NextCell.Address) End If Wend End If Set NextCell = Nothing Set Firstcell = Nothing Next oSheet End If End Sub At the message box near the end of this code you can insert the part that does what you need. Regards, Jan Karel Pieterse Excel MVP www.jkp-ads.com |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
Find and replace results can the appearance of find be different? | Excel Discussion (Misc queries) | |||
Minus Key Results in EXT Message in Status Bar | Excel Discussion (Misc queries) | |||
Format results in Message Box | Excel Discussion (Misc queries) | |||
How to use HLOOKUP for different sheets depending on results from 2 cells | Excel Worksheet Functions | |||
where to put results of find operation in find and replace functio | Excel Worksheet Functions |