Solved

Excel "Find and Replace" VBA - Export results to an array

Posted on 2016-07-28
6
17 Views
Last Modified: 2016-07-28
Hi Experts,

I'm trying to figure out how to make a call using VBA to access the "Find and Replace" menu:

 Screen shot of Find and Replace
I want to place the results (all fields) of the FindAll into an array for further processing.

thanks in advance,
Mark
0
Comment
Question by:SuperLight
  • 3
  • 3
6 Comments
 
LVL 48

Accepted Solution

by:
Rgonzo1971 earned 500 total points
ID: 41732565
Hi,

pls try ( fo r values, addresses or ranges)

Sub Macro()
Dim Sub Macro()
Dim aValues()
Dim aAddresses()
Dim aRanges()
    Set c = Cells.Find("MP", LookIn:=xlValues, Lookat:=xlPart)
    If Not c Is Nothing Then
        firstAddress = c.Address
        Idx = 0
        Do
        ReDim Preserve aValues(Idx)
        ReDim Preserve aAddresses(Idx)
        ReDim Preserve aRanges(Idx)
        aValues(Idx) = c.Value
        aAddresses(Idx) = c.Address
        Set aRanges(Idx) = c
        Set c = Cells.FindNext(c)
        Idx = Idx + 1
        Loop While Not c Is Nothing And c.Address <> firstAddress
    End If

End Sub

Open in new window

Regards
0
 

Author Closing Comment

by:SuperLight
ID: 41732798
Thanks!

Works a treat - with a little tweakage! ;o)

Kind Regards,
Mark
0
 

Author Comment

by:SuperLight
ID: 41732823
Quick follow-up...

Which parameter needs changing to Search the Workbook, not just the worksheet?

thanks,
Mark
0
Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
LVL 48

Expert Comment

by:Rgonzo1971
ID: 41732836
first what are looking for ranges or values?
0
 
LVL 48

Expert Comment

by:Rgonzo1971
ID: 41732845
then try
Sub Macro()
Dim aValues()
Dim aAddresses()
Dim aRanges()
Idx = 0
For Each ws In ActiveWorkbook.Worksheets
    With ws.Cells
        Set c = .Find("MP", LookIn:=xlValues, Lookat:=xlPart)
        If Not c Is Nothing Then
            firstAddress = "'" & ws.Name & "'!" & c.Address
            Do
                ReDim Preserve aValues(Idx)
                ReDim Preserve aAddresses(Idx)
                ReDim Preserve aRanges(Idx)
                aValues(Idx) = c.Value
                aAddresses(Idx) = "'" & ws.Name & "'!" & c.Address
                Set aRanges(Idx) = c
                Set c = .FindNext(c)
                Idx = Idx + 1
            Loop While Not c Is Nothing And "'" & ws.Name & "'!" & c.Address <> firstAddress
        End If
    End With
Next
End Sub

Open in new window

0
 

Author Comment

by:SuperLight
ID: 41732849
superb!
0

Featured Post

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

Suggested Solutions

A little background as to how I came to I design this code: Around 5 years ago I designed an add-in that formatted Excel files to a corporate standard, applying different cell colours and font type depending on whether the cells contained inputs,…
Approximate matching with VLOOKUP and MATCH seems to me to be a greatly under-used technique, and one which is vital for getting good performance out of large lookups. Until recently I would always have advised using an exact match for simplicity an…
This Micro Tutorial demonstrates how to create Excel charts: column, area, line, bar, and scatter charts. Formatting tips are provided as well.
This Micro Tutorial will demonstrate in Google Sheets how to use the HYPERLINK function to create live links inside your spreadsheet.

759 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now