help me with this code

bhandari

Active Member
Joined
Oct 17, 2017
Messages
359
Code:
Sub notworking()
With Worksheets(1)
WorksheetFunction.Sum (.Range(.Range("A1"), .Range("A7")))
End With
Sub moo()
WorksheetFunction.Sum (Worksheets(1).Range(Worksheets(1). _
Range("A1"), Worksheets("sheet2").Range("A7")))
End Sub

i dont understand what output iam geeting,i found this code in blog.i didnt get any error
code is excuted properly

can any one explain about this code
 

Excel Facts

Can you AutoAverage in Excel?
There is a drop-down next to the AutoSum symbol. Open the drop-down to choose AVERAGE, COUNT, MAX, or MIN
Well you should be getting an error as you have 2 subs without an End Sub in between.

Also you aren't putting/printing the result anywhere so you shouldn't get an output.

Perhaps it would be better if you just explained exactly what you want the code to do.
 
Upvote 0
Code:
Sub notworking()With Worksheets(1)
WorksheetFunction.Sum (.Range(.Range("A1"), .Range("A7")))
End With
End Sub
Sub moo()
WorksheetFunction.Sum (Worksheets(1).Range(Worksheets(1). _
Range("A1"), Worksheets("sheet2").Range("A7")))
End Sub
i think both are similar codes
iwas looking for output
can i get sum("A1:A7") by using above code?
 
Upvote 0
The first code already sums A1:A7 on Worksheets(1). As I stated you aren't telling it to put the result anywhere.
Code:
Sub Working()
    With Worksheets(1)
        [COLOR="#FF0000"][B]Cells(1, "B") =[/B] [/COLOR]WorksheetFunction.Sum(.Range(.Range("A1"), .Range("A7")))
    End With
End Sub
 
Upvote 0
Thank you i just need to understand the concept how Worksheetfunction.sum is working
i got it
Here is a similar code but its not working
Code:
Sub firstClass2()
cells(2, "B") = WorksheetFunction.Sum(Worksheets(1).Range(Worksheets(1). _
Range("A1"), Worksheets("sheet2").Range("A7")))
End Sub
 
Last edited:
Upvote 0

Forum statistics

Threads
1,216,165
Messages
6,129,250
Members
449,497
Latest member
The Wamp

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