Excel Macro : Select using macro

Pubblicato il: 02 aprile 2020
sul canale di: Rushikesh Shingare
53
2

1. Introduction


So let’s consider you have a excel workbook with multiple sheets with data in each sheet. First thing you do after opening workbook is to go to the appropriate sheet, so you cans tart workinhg and then probably start working on selected sheet with either selecting single cell or range of cells.
Same thing is apply for macro. You have to tell it from which sheet it has to start. If you don’t give the sheet reference it will start working on active sheet and that might give error or wrong output. so selection is needed
Let’s start with selecting things.

2. Selecting Sheet


As already discussed while writing any macro it is important to give reference of sheet because if you don’t then all operations will done on wrong sheet causing the wrong output or error in macro.
For selection. we use .select in macro. So to select sheet
Sub select_sheet()
Sheets("Test2").Select
End Sub
where Test2 is name of sheet
This will help you to select sheet. Now it does not matter which sheet is active when you run macro it will always find the sheet2 and start working on data. All the operations from after this line will executed on sheet 2 unless you again change it by typing same code with different sheet name.




3. Selecting Cell and Range


Now you are on your sheet, you can start working on data, as data is contains in cells, you have to select a proper cell, range of cells, complete row or complete column to work on. So if you have to change the data from particular cell you need to select that cell or say you need to delete or copy some range then you have to select that range.
To select cell :
Sub Select_cell()
Range("A1").Select
End Sub
This will go to / select Cell A1 on active sheet. Now can make the changes which will apply to selected cell that might be formatting of cell, copying, pasting, editing data of cell, etc.
Same goes for range.For selecting range you just need to give the start cell and end cell with colon in between them.
To select range:
Sub Select_range()
Range("A1:D5").Select
End Sub
This will select Cells from A1 till D5 on active sheet. Now can make the changes which will apply to selected cells that might be formatting of Range, copying, Deleting etc.
To select complete column give the column name i.e. A:D will select whole columns from A to D. Same goes with rows 1:4 will select whole rows from row 1 to 4.


In questa pagina del sito puoi guardare il video online Excel Macro : Select using macro della durata di ore minuti seconda in buona qualità , che l'utente ha caricato Rushikesh Shingare 02 aprile 2020, condividi il link con amici e conoscenti, su youtube questo video è già stato visto 53 volte e gli è piaciuto 2 spettatori. Buona visione!