Home

vba macro recorder

assuan franco
New 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

Related Conversations
Tabs and Dark Mode
cjc2112 in Discussions on
46 Replies
Extentions Synchronization
Deleted in Discussions on
3 Replies
Stable version of Edge insider browser
HotCakeX in Discussions on
35 Replies
How to Prevent Teams from Auto-Launch
chenrylee in Microsoft Teams on
30 Replies
flashing a white screen while open new tab
Deleted in Discussions on
14 Replies
Security Community Webinars
Valon_Kolica in Security, Privacy & Compliance on
13 Replies