Forum Discussion
assuan franco
Nov 08, 2018Copper Contributor
vba macro recorder
Hi!, when trying to record a macro (a quick example of assigning value 1 to cell F6) This is the result obtained Sub Macro1 () ' 'Macro1 Macro ' Range ("F6"). Select . = "1" End ...
Jamil
Nov 09, 2018Bronze Contributor
While Macro recorded is good to find the objective properties, it is not useful for writing codes, as it records unnecessary redundant steps of selecting and activating etc.
If you want to assign value in F6 first you need to know in which workbook you want to place it. is it the Active workbook or "ThisWorkbook"? the one that codes runs from.
then which sheet is it active sheet or a specific sheet
so here is the example to put the cell value in the workbook from which the code is ran from and the first sheet range F6
Sub test
Thisworkbook.worksheets(1).range("F6")=1
End sub
If you want to change it to active workbook and active sheet then below code.
Sub test
Activeworkbook.Activesheet.range("F6")=1
End sub
If you want to assign value in F6 first you need to know in which workbook you want to place it. is it the Active workbook or "ThisWorkbook"? the one that codes runs from.
then which sheet is it active sheet or a specific sheet
so here is the example to put the cell value in the workbook from which the code is ran from and the first sheet range F6
Sub test
Thisworkbook.worksheets(1).range("F6")=1
End sub
If you want to change it to active workbook and active sheet then below code.
Sub test
Activeworkbook.Activesheet.range("F6")=1
End sub