Written by Allen Wyatt (last updated November 3, 2018)
This tip applies to Excel 2007, 2010, 2013, 2016, 2019, and Excel in Microsoft 365
When Michael does a "Find All" operation in Excel, the program helpfully shows a list of all the cells containing whatever he is searching for. Michael would like to copy that list of cell addresses into another worksheet, so he wonders if there is a way to copy the list to the Clipboard so he can paste it into a worksheet.
There are a few ways you can accomplish this task, and most of them involve the use of macros. Before getting to the macro-based approaches, however, let's take a look at way you could access the addresses using named ranges and the Name Manager:
Figure 1. The Name Manager dialog box.
At this point you can copy the information in the Refers To box and paste it into whatever you want (including another worksheet). You'll need to massage the data a bit after you paste it, as the list is just that—a serial list of cell addresses.
Obviously, this affects your workbook, as it creates a named range. If you do it multiple times, you'll have multiple named ranges created. This can, of course, quickly get unwieldy if you need to perform the task quite often. This is where the macro solutions come into play. The following is an example of a macro that will search for a specific value and then place the address of every cell containing that value into another worksheet.
Sub CellAdressList() Dim c1 As String Dim nxt As String Sheets("Sheet1").Select Range("A1").Select Cells.Find(What:="qrs", After:=ActiveCell, _ LookIn:=xlValues, LookAt:=xlWhole, _ SearchOrder:=xlByRows, SearchDirection:=xlNext, _ MatchCase:=False, SearchFormat:=False).Activate c1 = ActiveCell.Address Sheets("Sheet2").Select Range("A1").Select Range("A1").Value = c1 Do Until nxt = c1 Sheets("Sheet1").Select Cells.FindNext(After:=ActiveCell).Activate nxt = ActiveCell.Address Sheets("Sheet2").Select ActiveCell.Offset(1, 0).Select ActiveCell.Value = nxt Loop ActiveCell.Value = "" End Sub
The macro makes a few assumptions. First, it assumes that you are searching for information on the worksheet named Sheet1. Second, it assumes you want the list of addresses placed in the worksheet named Sheet2. Finally, it assumes you are searching for the value "qrs" within Sheet1. All of these elements of the macro can be changed, if desired.
For something just a bit more flexible, consider the following macro. It assumes that you have already selected all the cells that contain the value you want. (In other words, you need to perform steps 1 through 3 of the steps near the beginning of this tip.) You can then run the macro.
Sub CopyFindAllSelection() Dim outcell As Range Dim c As Range Set outcell = Range("Sheet2!A1") For Each c In Selection outcell.Value = c.Address Set outcell = outcell.Offset(1, 0) Next End Sub
The result is that the addresses of the selected cells are placed into the Sheet2 worksheet. This macro is a bit more flexible because it allows you to find anything in any worksheet. The only part "hard coded" is the worksheet (Sheet2) into which the addresses are placed.
Note:
ExcelTips is your source for cost-effective Microsoft Excel training. This tip (13581) applies to Microsoft Excel 2007, 2010, 2013, 2016, 2019, and Excel in Microsoft 365.
Create Custom Apps with VBA! Discover how to extend the capabilities of Office 2013 (Word, Excel, PowerPoint, Outlook, and Access) with VBA programming, using it for writing macros, automating Office applications, and creating custom applications. Check out Mastering VBA for Office 2013 today!
You can use Find and Replace as a quick way to count any number of matches in your document. You cannot, however, use it ...
Discover MoreWildcard characters can be used within the Find and Replace tool, but what if you want to actually search for those ...
Discover MoreThe find and replace used in Excel is less powerful than its counterpart in Word, so it is not able to do some of the ...
Discover MoreFREE SERVICE: Get tips like this every week in ExcelTips, a free productivity newsletter. Enter your address and click "Subscribe."
There are currently no comments for this tip. (Be the first to leave your comment—just use the simple form above!)
Got a version of Excel that uses the ribbon interface (Excel 2007 or later)? This site is for you! If you use an earlier version of Excel, visit our ExcelTips site focusing on the menu interface.
FREE SERVICE: Get tips like this every week in ExcelTips, a free productivity newsletter. Enter your address and click "Subscribe."
Copyright © 2023 Sharon Parq Associates, Inc.
Comments