Solved

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

Posted on 2016-07-28
6
21 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 49

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
Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

 
LVL 49

Expert Comment

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

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

VMware Disaster Recovery and Data Protection

In this expert guide, you’ll learn about the components of a Modern Data Center. You will use cases for the value-added capabilities of Veeam®, including combining backup and replication for VMware disaster recovery and using replication for data center migration.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction While answering a recent question (http:/Q_27311462.html), I created an alternative function to the Excel Concatenate() function that you might find useful.  I tested several solutions and share the results in this article as well as t…
Some code to ensure data integrity when using macros within Excel. Also included code that helps secure your data within an Excel workbook.
Graphs within dashboards are meant to be dynamic, representing data from a period of time that will change each time the dashboard is updated with new data. Rather than update each graph to point to a different set within a static set of data, t…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

773 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