Macro Runtime errors

M

mhsmalls

I am running EXCEL 10. I am trying to create a macro that sums up numbers from B5:D5, B8;D8,B11:D11, etc.. The macro works fine until I get to cellsB47:D:47 then when I try to run the macro I get "Runtime error '1004':application defined or object defined error. I have no idea what I am doing wrong and when I step into the macro I can't make heads or tales of the syntext. Please help!
 
C

Claus Busch

Hi,

Am Wed, 19 Mar 2014 04:10:27 -0700 (PDT) schrieb (e-mail address removed):
I am running EXCEL 10. I am trying to create a macro that sums up numbers from B5:D5, B8;D8,B11:D11, etc.. The macro works fine until I get to cells B47:D:47 then when I try to run the macro I get "Runtime error '1004':application defined or object defined error. I have no idea what I am doing wrong and when I step into the macro I can't make heads or tales of the syntext. Please help!

can you show us your code?

Regards
Claus B.
 
M

mhsmalls

I am running EXCEL 10. I am trying to create a macro that sums up numbersfrom B5:D5, B8;D8,B11:D11, etc.. The macro works fine until I get to cellsB47:D:47 then when I try to run the macro I get "Runtime error '1004':application defined or object defined error. I have no idea what I am doing wrong and when I step into the macro I can't make heads or tales of the syntext. Please help!

=SUM(B5:D5,B8:D8,B11:D11,B14:D14,B17:D17,B20:D20,B23:D23,B26:D26,B29:D29,B32:D32,B35:D35,B38:D38,B41:D41,B44:D44,B47:D47,B50:D50,B53:D53,B56:D56,B59:D59,B62:D62,B65:D65,B68:D68,B71:D71,B74:D74,B77:D77,)
 
C

Claus Busch

Hi,

Am Wed, 19 Mar 2014 11:20:38 -0700 (PDT) schrieb (e-mail address removed):
=SUM(B5:D5,B8:D8,B11:D11,B14:D14,B17:D17,B20:D20,B23:D23,B26:D26,B29:D29,B32:D32,B35:D35,B38:D38,B41:D41,B44:D44,B47:D47,B50:D50,B53:D53,B56:D56,B59:D59,B62:D62,B65:D65,B68:D68,B71:D71,B74:D74,B77:D77,)

if you use a function in VBA you have to write it like:
=Worksheetfunction.Sum(....
To make the code more readable try:
Sub Sum()
Dim myStart As Long
Dim myStop As Long
Dim i As Long
Dim mySum As Double

myStart = 5
myStop = 77

For i = myStart To myStop Step 3
mySum = mySum + WorksheetFunction.Sum(Range(Cells(i, 2), Cells(i,
4)))
Next
Range("B1") = mySum
End Sub

Or:

Sub Sum_2()
Dim myStart As Long
Dim myStop As Long
Dim i As Long
Dim myRng As Range

myStart = 5
myStop = 77

For i = myStart To myStop Step 3
If myRng Is Nothing Then
Set myRng = Range(Cells(i, 2), Cells(i, 4))
Else
Set myRng = Union(myRng, Range(Cells(i, 2), Cells(i, 4)))
End If
Next
Range("C1") = WorksheetFunction.Sum(myRng)
End Sub


Regards
Claus B.
 
M

mhsmalls

I am running EXCEL 10. I am trying to create a macro that sums up numbersfrom B5:D5, B8;D8,B11:D11, etc.. The macro works fine until I get to cellsB47:D:47 then when I try to run the macro I get "Runtime error '1004':application defined or object defined error. I have no idea what I am doing wrong and when I step into the macro I can't make heads or tales of the syntext. Please help!

Thanks for the help but is there any way I can do bu using the "Record Macro" function under the "developer" tab. I'm confused as to how I'm supposedto write the instructions in the VBA module. Also, I can't figure out whymy other macro's work and this one doesn't.
 
C

Claus Busch

Hi,

Am Thu, 20 Mar 2014 03:50:19 -0700 (PDT) schrieb (e-mail address removed):
Thanks for the help but is there any way I can do bu using the "Record Macro" function under the "developer" tab. I'm confused as to how I'm supposed to write the instructions in the VBA module. Also, I can't figure out why my other macro's work and this one doesn't.

your macro fails because of false syntax.
Try:
Range("A1") = WorksheetFunction.Sum(Range("B5:D5,B8:D8,B11:D11,B14:D14,"
_
& "B17:D17,B20:D20,B23:D23,B26:D26,B29:D29,B32:D32,B35:D35,B38:D38,"
_
& "B41:D41,B44:D44,B47:D47,B50:D50,B53:D53,B56:D56,B59:D59,B62:D62,"
_
& "B65:D65,B68:D68,B71:D71,B74:D74,B77:D77"))

Or:
Range("B1").Formula = "=SUM(B5:D5,B8:D8,B11:D11,B14:D14,B17:D17," _
& "B20:D20,B23:D23,B26:D26,B29:D29,B32:D32,B35:D35,B38:D38,B41:D41,"
_
& "B44:D44,B47:D47,B50:D50,B53:D53,B56:D56,B59:D59,B62:D62,B65:D65,"
_
& "B68:D68,B71:D71,B74:D74,B77:D77)"


Regards
Claus B.
 
M

mhsmalls

I am running EXCEL 10. I am trying to create a macro that sums up numbersfrom B5:D5, B8;D8,B11:D11, etc.. The macro works fine until I get to cellsB47:D:47 then when I try to run the macro I get "Runtime error '1004':application defined or object defined error. I have no idea what I am doing wrong and when I step into the macro I can't make heads or tales of the syntext. Please help!

I went into the Developer's tab, clicked "Record Macro" and began to type in the Syntax you gave me. It probably didn't work because I didn't type itin correctly. Am I supposed to type in, and I quote(without using quote symbol) Range("B1").Formula="SUM(B5:D5,B8:D8,B11:D11,etc........? I can domanually do use =Sum(B5:D5, etc... and it works well, I just wanted to create a Macro to save time. Do I include the " and & and _ when I'm writing the syntax? I tried it and it didn't work. If you think I'm stupid, it's O.K. I'm just trying to understand
 
C

Claus Busch

Hi,

Am Fri, 21 Mar 2014 05:24:42 -0700 (PDT) schrieb (e-mail address removed):
I went into the Developer's tab, clicked "Record Macro" and began to type in the Syntax you gave me. It probably didn't work because I didn't type it in correctly. Am I supposed to type in, and I quote(without using quote symbol) Range("B1").Formula="SUM(B5:D5,B8:D8,B11:D11,etc........? I can do manually do use =Sum(B5:D5, etc... and it works well, I just wanted to create a Macro to save time. Do I include the " and & and _ when I'm writing the syntax? I tried it and it didn't work. If you think I'm stupid, it's O.K. I'm just trying to understand

if you want to record a macro start recorder and make everthing you want
to record by hand. If your work is done stop the recorder.
If you want do work with my macros press Alt+F11 => Insert Module and
paste the code into the code window of the module. Then back in the
sheet run the macro.

Regards
Claus B.
 
C

Claus Busch

Hi,

Am Fri, 21 Mar 2014 05:24:42 -0700 (PDT) schrieb (e-mail address removed):
I went into the Developer's tab, clicked "Record Macro" and began to type in the Syntax you gave me. It probably didn't work because I didn't type it in correctly. Am I supposed to type in, and I quote(without using quote symbol) Range("B1").Formula="SUM(B5:D5,B8:D8,B11:D11,etc........? I can do manually do use =Sum(B5:D5, etc... and it works well, I just wanted to create a Macro to save time. Do I include the " and & and _ when I'm writing the syntax? I tried it and it didn't work. If you think I'm stupid, it's O.K. I'm just trying to understand

look here:
https://onedrive.live.com/?cid=9378...#cid=9378AAB6121822A3&id=9378AAB6121822A3!326
for workbook "Sum2"
Right click and download the file because macros are disabled in
OneDrive. Open the workbook => Press Alt+F11 to see where the code
should be placed.


Regards
Claus B.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top