Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 516
Default Run-time error from my code

I have this code that is placing a formula in a range of cells if a control checkbox(cbExempt) is false. Then if cbExempt is true, it is clearing the contents of that same range of cells. I am getting a runtime error(1004):Application-defined or object-defined error when I run this code. The problem seems to be the line where it places the formula in the range of cells. At least that is the line that the debugger is highlighting. Any suggestions would be great. Thanks. Matt

Public Sub Formula()
If Worksheets("TIME AND LEAVE").cbExempt.Value = False Then
Worksheets("TIME AND LEAVE").Range("C31,E31,G31,I31,K31,M31,O31").Formu la = "=IF(RC[1] < R[-21]C[1],'ERROR','')"
Else
Worksheets("TIME AND LEAVE").Range("C31,E31,G31,I31,K31,M31,O31").Clear Contents
End If
End Sub
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 57
Default Run-time error from my code


-----Original Message-----
I have this code that is placing a formula in a range of

cells if a control checkbox(cbExempt) is false. Then if
cbExempt is true, it is clearing the contents of that same
range of cells. I am getting a runtime error
(1004):Application-defined or object-defined error when I
run this code. The problem seems to be the line where it
places the formula in the range of cells. At least that
is the line that the debugger is highlighting. Any
suggestions would be great. Thanks. Matt

Public Sub Formula()
If Worksheets("TIME AND LEAVE").cbExempt.Value =

False Then
Worksheets("TIME AND LEAVE").Range

("C31,E31,G31,I31,K31,M31,O31").Formula = "=IF(RC[1] < R[-
21]C[1],'ERROR','')"
Else
Worksheets("TIME AND LEAVE").Range

("C31,E31,G31,I31,K31,M31,O31").ClearContents
End If
End Sub
.
Try using .select then selection.clearcontents


then range("a1").select to get back to a "home" position

nath
  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 516
Default Run-time error from my code

I get the same problem. My problem is with the .formula line of code. Thanks for trying.
Matt

"Matt" wrote:

I have this code that is placing a formula in a range of cells if a control checkbox(cbExempt) is false. Then if cbExempt is true, it is clearing the contents of that same range of cells. I am getting a runtime error(1004):Application-defined or object-defined error when I run this code. The problem seems to be the line where it places the formula in the range of cells. At least that is the line that the debugger is highlighting. Any suggestions would be great. Thanks. Matt

Public Sub Formula()
If Worksheets("TIME AND LEAVE").cbExempt.Value = False Then
Worksheets("TIME AND LEAVE").Range("C31,E31,G31,I31,K31,M31,O31").Formu la = "=IF(RC[1] < R[-21]C[1],'ERROR','')"
Else
Worksheets("TIME AND LEAVE").Range("C31,E31,G31,I31,K31,M31,O31").Clear Contents
End If
End Sub

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 45
Default Run-time error from my code

You need to modify your formula line to the following:

Worksheets("Sheet1").Range("C31,E31,G31,I31,K31,M3 1,O31").FormulaR1C1 =
"=IF(RC[1] < R[-21]C[1],""ERROR"","""")"

Your error was in how you were defining your TRUE and FALSE items in the IF
statement. You were using single ticks (') where Excel requires double
quotes around a string in this situation.

HTH

--
Michael J. Malinsky
Pittsburgh, PA

"I am a bear of very little brain, and long
words bother me." -- AA Milne, Winnie the Pooh

"Matt" wrote in message
...
I have this code that is placing a formula in a range of cells if a

control checkbox(cbExempt) is false. Then if cbExempt is true, it is
clearing the contents of that same range of cells. I am getting a runtime
error(1004):Application-defined or object-defined error when I run this
code. The problem seems to be the line where it places the formula in the
range of cells. At least that is the line that the debugger is
highlighting. Any suggestions would be great. Thanks. Matt

Public Sub Formula()
If Worksheets("TIME AND LEAVE").cbExempt.Value = False Then
Worksheets("TIME AND

LEAVE").Range("C31,E31,G31,I31,K31,M31,O31").Formu la = "=IF(RC[1] <
R[-21]C[1],'ERROR','')"
Else
Worksheets("TIME AND

LEAVE").Range("C31,E31,G31,I31,K31,M31,O31").Clear Contents
End If
End Sub



Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Visual Basic Error Run Time Error, Type Mismatch Meg Partridge Excel Discussion (Misc queries) 12 September 10th 08 06:10 PM
Run time error 1004, General ODBC error [email protected] New Users to Excel 0 September 19th 05 01:41 AM
How can I still go to the error-code after a On Error Goto? Michel[_3_] Excel Programming 2 May 4th 04 04:21 AM
Code Error - Run Time Error 5 (Disable Cut, Copy & Paste) Tim[_36_] Excel Programming 4 April 23rd 04 02:53 AM
Code Run-time error '1004' pjhageman[_5_] Excel Programming 3 January 11th 04 12:24 AM


All times are GMT +1. The time now is 04:46 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"