Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

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

Posted on 2016-07-28
6
Medium Priority
?
37 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 53

Accepted Solution

by:
Rgonzo1971 earned 2000 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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 53

Expert Comment

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

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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

When you see single cell contains number and text, and you have to get any date out of it seems like cracking our heads.
If you need to forecast numbers -- typically for finance -- the Windows and Mac versions of Excel 2016 have a basket of tools to get the job done.
This Micro Tutorial will demonstrate in Microsoft Excel how to add style and sexy appeal to horizontal bar charts.
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…

885 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