Monday, June 27, 2011

GO TO function and Special Cells method.

Go To function :-
Are you familiar with the Go To Special functionality in Excel? This is another chunk of functionality
that many Excel users either don’t know exists or don’t take advantage of. Check it out in Excel; select
Edit > Go To and then click the Special button at the bottom left corner of the Go To dialog box.
If you haven’t used this yet, let me tell you—this handy little dialog box can be a real time-saver.
Quick, what’s the easiest way to select all of the text values in the range, The answer is Press CTRL+G to display the Go To dialog box and then click the Special button.
Choose the Constants option with only the Text checkbox checked and click OK.

SpecialCells method :-
Most of the functionality served up by Go To Special can be accessed programmatically using the
SpecialCells method.
YourSearchRange.SpecialCells(Type As XlCellType, [Value]) As Range

The Type parameter is required and should be one of the xlCellType constants:-

xlCellType Constants for Use with the SpecialCells Method

Constant                                                 Selects
xlCellTypeAllFormatConditions        Cells of any format
xlCellTypeAllValidation                    Cells using Data Validation
xlCellTypeBlanks                             Empty Cells
xlCellTypeComments                       Any Cell Containing a comment
xlCellTypeConstants                        Cells with constant (or literal) values
xlCellTypeFormulas                         Cells with formulas
xlCellTypeLastCell                            The last cell in the used range
xlCellTypeSameFormatConditions     Cells having the same format
xlCellTypeSameValidation    Cells having the same data validation criteria
xlCellTypeVisible                              All visible cells

If you chose either xlCellTypeConstants or xlCellTypeFormulas for the Type parameter, you can
further define which cells to select using the optional Value parameter. By default, all constants or
formulas are selected. Use one or more of the following constants: xlErrors, xlLogical, xlNumbers, or
xlTextValues. For example, to duplicate the functionality you’d use something similar to this:

ActiveSheet.Cells.SpecialCells(xlCellTypeConstants, xlTextValues)

Note that you can specify more than one kind of value by adding constants together.

ActiveSheet.Cells.SpecialCells(xlCellTypeConstants, _
xlErrors + xlTextValues)

One more thing, SpecialCells requires special care. If SpecialCells doesn’t find any special cells, it
generates a run-time error, so be sure to use error handling in any procedure that uses SpecialCells.

No comments:

Subscribe Now: From your browser

Search:

Learn Office Excel