vba macro recorder

Copper Contributor

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 Sub

 

an incomplete code that does not run

try to repair Office, uninstall and install it, delete the settings in the registry and nothing worked.

4 Replies

the following is what I got..

 

 

Sub Macro1()
'
' Macro1 Macro
'

'
Range("F6").Select
ActiveCell.FormulaR1C1 = "=1"
Range("F7").Select
End Sub

 

is an example of what the editor does, but it does it with any object, there are times that I do not know some code and with the macro recorder I get an idea of how to do it,

 

other example, I add a sheet

 

Sub Macro2()
'
' Macro2 Macro
'

'
.Add :=
.Enabled.Select
End Sub

VB Editor is a nice way of making automated procedures. I often use it and when I bumped into a snag, I post that problem at this forum to get some solutions. There are many good people here who can help. Just post whatever problem you encountered. Suggest that you post your queries one at a time - this way you can learn better, don't go for a quick fix.
thanks..
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