Excel VBA - Last
Excel vba - Method SpecialCells
This method (SpecialCells) is helpful to return references to ranges with certain characteristics:
For example, we obtained by the method SpecialCells references ranges:
This would be the syntax for an object range of cells
The cell range is where you want to search for cells with certain characteristics we
Range (rangodeCeldas). SpecialCells (Type, Value)
Parameters would be the ff:
Type: parameter represnta mandatory type cells to be included. ----
Value: Optional parameter
-----
If PARAMTR "Type" is (xlCellTypeConstants) or (xlCellTypeFormulas), the parameter "Value" will determine what types of cells that are included in the returned range.
a) The constants for the types of cells to find (XlCellType)
xlCellTypeAllFormatConditions. Cells with either format.
xlCellTypeAllValidation. Cells validation criteria.
xlCellTypeBlanks. Empty cells.
xlCellTypeComments. Cells containing notes.
xlCellTypeConstants. Cells containing constants.
xlCellTypeFormulas. Cells containing formulas.
xlCellTypeLastCell. The last cell in the range.
xlCellTypeSameFormatConditions. Cells having the same format.
xlCellTypeSameValidation. Cells that have the same criteria for validation.
xlCellTypeVisible. All visible cells.
b) the constant for the second paarmetro is opcionl (XlSpecialCellsValue) Value
This second parametyro allow us to refine our search for cells specialty was filtered by:
xlErrors
xlLogical
xlNumbers
xlTextValues \u200b\u200b
example
---- ---- September
rng = Range (Turanga). SpecialCells (xlCellTypeFormulas, xlErrors) 'failed formulas
------------------- MsgBox rng.Address
---------------
Excel Vba Example code
SpecialCells Sub
VbaExcelCode_SampleSpeciallCells ()
'MacroVbaExcel: Jesus Martin Serrano Panduro
Dim rng As Range Dim Turanga
Turanga As String = "A1: C13"
September
rng = Range (Turanga). SpecialCells (xlCellTypeFormulas, xlNumbers ) 'MsgBox
formulas rng.Address
September
rng = Range (Turanga). SpecialCells (xlCellTypeFormulas, xlErrors)' failed formulas
rng.Address
September MsgBox rng = Range (Turanga). SpecialCells (xlCellTypeComments) ' Cells with comments
rng.Address
Debug.Print 'Note:
' debug using print can write the value of a variable, etc in the
immediate window 'To see the immediate window while on the vba editor must press control and ready
G' is particularly useful for analyzing the values \u200b\u200bthat takes a variable in vba procedure
End Sub Sub
VbaExcelCode_formatEmptyCells ()
'MacroVbaExcel: Jesus Martin Serrano Panduro
ActiveSheet.UsedRange.SpecialCells _
(xlCellTypeBlanks). Interior.Color
= 3732' Note: If there are no cells will be returned the error 1004
cells were not found ' validate that you do in this case to not display the raw message.
End Sub Sub
vbaExcelCode_rowTestCells ()
'MacroVbaExcel: Jesus Martin Serrano Panduro
' Test the routines in Excel ff 2007 0 2010 - Rows of the version of Excel (1048576)
'as indeed this worked correctly in Excel 2003-Rows of the version of Excel (65536) or earlier that had not as many rows
'this is another reason more torque than restrict your searches of cells or cell range used special ActiveSheet.UsedRange.Cells.Count
MsgBox MsgBox
ActiveSheet.Cells.Count'
overflow error 6
End Sub Sub
VbaExcelCode_findLastCells ()
'MacroVbaExcel: Jesus Martin Serrano Panduro
' to end specialcells to make it simpler
clear 'actively used cell ultiam
ActiveSheet.Cells.SpecialCells (xlCellTypeLastCell).
Activate End Sub