Ctrl F, export results

ellison

Active Member
Joined
Aug 1, 2012
Messages
356
Office Version
  1. 365
Platform
  1. Windows
Hi, I'm wondering if there is a way of exporting the results of a Ctrl Find?

I've seen that you can select them all and copy them, but only if the selected cells are next to each other. (But that doesn't happen very often for us!).

(The other challenge we have is that we'd like to use this on different files & they'll often have different headers, sheet names etc


Ctrl-Find-Export-Results-01.xlsx
ABCD
1RowCol-BCol-CCol-C
22alphaalpha 9
33beta
44charliecharlie 6
55deltadelta14
66echoecho 5
77foxtrotfoxtrot 112
88
99golfgolf 4
1010hotelhotel 4
Sheet1



Thanks for any help you could provide!
 

Attachments

  • ctrl-f-pic-01.png
    ctrl-f-pic-01.png
    38.7 KB · Views: 48
Perhaps the below will give you some ideas, you could refine the code quite a bit to be honest, at this stage it is more pseudocode :
VBA Code:
Sub FindLoop()
    Dim addVar() As String, valVar() As Variant, x As Long
    Dim rngFA As String, outIB As Range
    Dim rng As Range, fRng As Range
    Dim sIn As Integer, VorF As Integer
   
    Set rng = ActiveSheet.Range("B2:E10")
   
    sIn = InputBox("1 = Values, 2 = Formula", "LookIn") ' does not have to be 2, anything other than 1 will search Formula
    VorF = InputBox("1 = Values, 2 = Formula", "Return values or formula") ' does not have to be 2, anything other than 1 will return formula
   
    Set fRng = rng.Find(InputBox("Value to find", "Find what?"), , IIf(sIn = 1, xlValues, xlFormulas), xlPart)
   
    If Not fRng Is Nothing Then
        rngFA = fRng.Address
        Do
            If VorF = 1 Then
                ReDim Preserve addVar(x): addVar(x) = fRng.Address(, , , 1)
                ReDim Preserve valVar(x): valVar(x) = fRng.Value
                x = x + 1
            ElseIf Application.IsFormula(fRng) = True Then
                ReDim Preserve addVar(x): addVar(x) = fRng.Address(, , , 1)
                ReDim Preserve valVar(x): valVar(x) = fRng.Formula
                x = x + 1
            End If
            Set fRng = rng.FindNext(fRng)
        Loop Until fRng Is Nothing Or fRng.Address = rngFA
    End If
   
    Set outIB = Application.InputBox("Select range", Type:=8)
   
    outIB.Resize(UBound(addVar) + 1, 1) = Application.Transpose(addVar)
    outIB.Offset(, 1).Resize(UBound(valVar) + 1, 1) = Application.Transpose(valVar)
End Sub
 
Upvote 0

Excel Facts

Can Excel fill bagel flavors?
You can teach Excel a new custom list. Type the list in cells, File, Options, Advanced, Edit Custom Lists, Import, OK
Hi that is astonishingly great!

1 final fly in the ointment seems to be that the code is only displaying values (even if you opt for the formula option)

(I've tried to search a workaround for this but I'm drawing a blank)

Would you have any pointers?!
 
Upvote 0
Do you mean is is displaying the value that is the result of a formula?

For example, it will show: "echo" instead of "=+B6"

Have you selected the resulting cell as it should contain the formula.
 
Upvote 0
Yes what you've said is right..

so even if I select formula, it's still showing the value (aka "result of the formula") - as opposed to the actual formula
 
Upvote 0
You could try changing this line:
VBA Code:
ReDim Preserve valVar(x): valVar(x) = fRng.Formula
With:
VBA Code:
ReDim Preserve valVar(x): valVar(x) = "'" & fRng.Formula
 
Upvote 0
Solution
You could try changing this line:
VBA Code:
ReDim Preserve valVar(x): valVar(x) = fRng.Formula
With:
VBA Code:
ReDim Preserve valVar(x): valVar(x) = "'" & fRng.Formula
That's cracked it!!!! Brilliant .... and H-U-G-E thanks for your help! 💪👍
 
Upvote 0

Forum statistics

Threads
1,224,817
Messages
6,181,144
Members
453,021
Latest member
Justyna P

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top