From macro to vba

montecarlo2012

Well-known Member
Joined
Jan 26, 2011
Messages
986
Office Version
  1. 2010
Platform
  1. Windows
Hello everyone.
I am here trying to see the transformation from a simple Macro to a Code, I know guy for you is something so Simple, but “ sorry “ no for me, I am a new self-thaught bee.
I just sum two numbers with the macro recorder I got this:

Range("H2").Select
ActiveCell.Formula = "=SUM(A2:B2)"

So with my Basic knowledge I see that H2 has to be a variable, sum I can think as a total, or another variable, and the two location as well, so I got this:

Sub real_code()
Dim H As Integer, A As Integer, B As Integer
A = Range("A2").Value: B = Range("B2").Value
H = A + B
Range("H1").Value = H
End Sub

And “”Bingo”” work well.

But now I intent to transform the macro using the function COUNT,

Sub C_m()
Range("H6").Select
ActiveCell.Formula = "=COUNT(B:B)"
End Sub

BUT then, I realize my logic do not worked as before, the only thing
So far, I can see is, must be a loop, how I will deduce that?, “ I don’t know” that why I am here.
Thank you.
 

DanteAmor ............excellent job, thank you. is exactly the result I expect.
 
Upvote 0

Excel Facts

Format cells as time
Select range and press Ctrl+Shift+2 to format cells as time. (Shift 2 is the @ sign).
I'm glad to help you. I appreciate your kind comments.
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,177
Members
453,021
Latest member
Justyna P

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top