Written by Allen Wyatt (last updated June 28, 2021)
This tip applies to Excel 2007, 2010, 2013, and 2016
When you use the Find command, Excel defaults to "search by row" as the order it will use in looking for information. Your needs may vary, however; you may have a need to search by column most of the time. You can certainly change this setting when you start the search, but wouldn't it be nice to change the default so that Excel starts out by searching columns?
Unfortunately, there is no setting that you can specify so that Excel remembers how you want to do your search. You can, however, use a macro to set the default searching order. Consider the following example:
Private Sub Workbook_Open() On Error Resume Next Cells.Find("", , , , xlByColumns, , , False) = True End Sub
This macro does nothing but change the search order to columns. After it is run (in other words, after you open the workbook), subsequent searches will default to searching by column.
The fact that Excel remembers the last-used search order for all subsequent searches during the current Excel session can be used to your advantage. The following macro does essentially the same thing as the previous example, except it also closes the workbook:
Sub Auto_Open() Worksheets("sheet1").Cells.Find _ What:="", _ After:=ActiveCell, _ LookIn:=xlFormulas, _ LookAt:=xlWhole, _ SearchOrder:=xlByColumns, _ SearchDirection:=xlNext, _ MatchCase:=True ThisWorkbook.Close savechanges:=False End Sub
If you put this macro into a blank workbook and then save the workbook in your xlStart folder, it would be opened every time you start Excel. When opened, the workbook does a single search using the settings you want, and then closes itself. The net result is that your search order is set to columns, and subsequent searches will occur the way you want them to.
Note:
ExcelTips is your source for cost-effective Microsoft Excel training. This tip (12494) applies to Microsoft Excel 2007, 2010, 2013, and 2016. You can find a version of this tip for the older menu interface of Excel here: Searching by Columns, by Default.
Solve Real Business Problems Master business modeling and analysis techniques with Excel and transform data into bottom-line results. This hands-on, scenario-focused guide shows you how to use the latest Excel tools to integrate data from multiple tables. Check out Microsoft Excel 2013 Data Analysis and Business Modeling today!
When you search for information in a worksheet, you expect Excel to return results that make sense. If you don't get a ...
Discover MoreSearching for information in an Excel worksheet generally goes very smoothly. There can be times, however, when the ...
Discover MoreFinding and replace dates contained within other text in a cell can be a bit tricky. This tip looks at some approaches to ...
Discover MoreFREE SERVICE: Get tips like this every week in ExcelTips, a free productivity newsletter. Enter your address and click "Subscribe."
2021-07-01 15:28:34
J. Woolley
@Caroline
Put the following VBA in a workbook's ThisWorkbook module. Whenever you open that workbook (.xlsm), the specified Look in:, Match entire..., and Search: parameters of the Find/Replace dialog will be set. These will persist until changed and apply to all workbooks until Excel is closed.
Private Sub Workbook_Open()
' modify Find/Replace defaults; edit Const values as desired
Const LookIn = xlValues ' default is xlFormulas
Const LookAt = xlWhole ' default is xlPart
Const SearchOrder = xlByColumns ' default is xlByRows
ActiveCell.Find vbNullString, , LookIn, LookAt, SearchOrder
End Sub
See https://docs.microsoft.com/en-us/office/vba/api/excel.range.find
and https://sites.google.com/view/MyExcelToolbox/
2021-06-30 08:39:00
Caroline
It would also be great to have Excel look in Values instead of in Formulas by default. Is there a way to do that?
2017-09-30 11:07:05
V.S.Rawat
It is so cruel of MS that they didn't give an in built option to switch between column-wise or row-wise find-replace.
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