Stop searching. Start learning and developing your excel skills.
Macro
VBA
Formula
Function
Shortcut
Tricks

Showing posts with label Selection. Show all posts
Showing posts with label Selection. Show all posts
Browse » Home » Posts filed under Selection

Select Columns Contain Error

February 06, 2024 |

''' If Error GoTo NextCode

On Error GoTo NextCode

''' Select column A until the last column

Columns("A:A").Select

Range(Selection, Selection.End(xlToRight)).Select

''' Select cells with error

Selection.SpecialCells(xlCellTypeConstants, 16).Select

''' Select columns for cells with error and delete the columns

Selection.EntireColumn.Delete

NextCode:

NextCode Here.. 

Select from Cell A1 until the Last Cell

February 06, 2024 |

Dim rLastColumnLetter As String

Dim rLastRowNumber As Long

rLastColumnLetter = Split(Columns(Range("A1").End(xlToRight).Column).Address(, False), ":")(1)

rLastRowNumber = Range("D" & Rows.Count).End(xlUp).Row

Select from cell A1 until the last cell.

Range("A1:" & rLastColumnLetter & rLastRowNumber)

VBA to Select Cell from A Reference Cell

July 19, 2020 |
OFFSET

The OFFSET function returns a cell that is a specified number of rows and/or columns from the reference cell.

The Syntax

OFFSET (number of rows to move UP/DOWN, number of columns to move RIGHT/LEFT)

Example

Range("A1").Offset(1, 0).Select

Means move one row down from cell A1. The cell selected will now be A2.

Range("A1").Offset(0, 1).Select

Means move one column right to cell A1. The cell selected will now be B1.

Range("A1").Offset(1, 1).Select

Means move one column right and one row down from cell A1. The cell selected will now be B2.

VBA To Select Until Last Column in Blank Row

August 09, 2018 |
Say in a blank row, you want to select from selected cell until last column. If you use ctrl + shift + > key, excel will bring you until the end of excel (column XFD in excel 2016). So the easiest way is by identifying last column with header and then use a macro to select until the last column.

Say your header is in row #4, and you want to select from cell BE1 until last column with data in the same row:

Dim k as long
With ActiveSheet
   k = .Cells(4, .Columns.Count).End(xlToLeft).Column
End With
Range(Range("BE1"), Cells(1, k)).Select

VBA To Select Worksheets

June 03, 2017 |
This is also related to below queries:
  1. vba select sheet and cell
  2. excel vba activate workbook
  3. select active sheet vba
  4. excel vba select sheet variable name
  5. excel vba worksheet activate event
  6. excel vba select multiple sheets

The Code:
Sheets("Sheet1").Select
''' To select one worksheet
Sheets(Array("Sheet1", "Sheet2", "Sheet3")).Select
'''To select multiple worksheets

VBA To Select Variable Columns

June 03, 2017 |
This is also related to below queries:
  1. dynamic range excel vba
  2. excel vba dynamic range column
  3. excel macro dynamic range
  4. vba range with variable row number
  5. excel vba select range with variable number of rows
The Code:
Columns("A:D").Select
''' To select whole column A until column D
Range("X:X,AB:AB").Select
''' To select column X and column AB only
Note:
  1. Please change Columns("A:D") to your columns. Example: Columns("A:B") or Columns("A:Z")
  2. Please change Range("X:X,AB:AB") to your columns. Example: Range("A:A,C:C,AA:AB"). You may add more columns by just adding a comma before and after a column/ columns range

VBA To Select All Cells

June 03, 2017 |
This is also related to below queries:
  1. vba select all cells
  2. vba ctrl a
  3. select entire worksheet excel
  4. vba copy all cells
  5. how to select entire worksheet in excel vba
The Code:
Cells.Select

VBA To Select Last Columns

June 03, 2017 |
This is also related to below queries:
  1. columns.count vba
  2. select last row vba
  3. excel vba last used column
  4. vba find last row with data
  5. excel vba find last row with data in range
The code:
''' Select last column
Range("A1").Select
    Selection.End(xlToRight).Select
    Range(ActiveCell, ActiveCell.Offset(0, 0)).EntireColumn.Select
''' Select last 2 columns
Range("A1").Select
    Selection.End(xlToRight).Select
    Range(ActiveCell, ActiveCell.Offset(0, -1)).EntireColumn.Select
''' Select last 3 columns
Range("A1").Select
    Selection.End(xlToRight).Select
    Range(ActiveCell, ActiveCell.Offset(0, -2)).EntireColumn.Select