![]() |
Trouble entering formula into cell
I wrote a macro to reformat a report. As it goes from row to row rearranging
the data from the report, there are some cells where I need the code to enter a formula into the cell. However, when it hits that part I keep getting error 1004 - application or user-defined error. Here is the portion of the code that gives me fits: Range("H" & Count + 2).Value = Range("F" & Count + 6).Value Range("I" & Count + 2).Value = "" Range("J" & Count + 2).Formula = "=IF(I" & Count + 2 & "=""00/00/0000"",0,IF(I" & Count + 2 & "-H" & Count + 2 & _ "1,1,0)" I get the error when it hits the 'Range("J"' line. For referrence, the value placed into column H is a date and Count is Dim'd as Long. I'm not worried that the result of the formula (that I'm trying to put in column J) will give an error, I just want the formula there. I've even tried changing the code so that it always puts "00/00/0000" in column I, but it didn't work. |
Trouble entering formula into cell
You needed to add a ")" at the end.
Range("J" & Count + 2).Formula = "=IF(I" & Count + 2 & "=""00/00/0000"",0,IF(I" & Count + 2 & "-H" & Count + 2 & "1,1,0))" Hope this helps! If so, let me know, click 'YES" below. -- Cheers, Ryan "Luke" wrote: I wrote a macro to reformat a report. As it goes from row to row rearranging the data from the report, there are some cells where I need the code to enter a formula into the cell. However, when it hits that part I keep getting error 1004 - application or user-defined error. Here is the portion of the code that gives me fits: Range("H" & Count + 2).Value = Range("F" & Count + 6).Value Range("I" & Count + 2).Value = "" Range("J" & Count + 2).Formula = "=IF(I" & Count + 2 & "=""00/00/0000"",0,IF(I" & Count + 2 & "-H" & Count + 2 & _ "1,1,0)" I get the error when it hits the 'Range("J"' line. For referrence, the value placed into column H is a date and Count is Dim'd as Long. I'm not worried that the result of the formula (that I'm trying to put in column J) will give an error, I just want the formula there. I've even tried changing the code so that it always puts "00/00/0000" in column I, but it didn't work. |
Trouble entering formula into cell
Sheesh. I tied my brain in knots trying to figure out what I did wrong, even
meticulously pouring over the quotes just to make sure I got them right. Never even began to suspect I left out a parenthesis at the end. It's always the little things that get you. Thanks for the extra pair of eyes. "Ryan H" wrote: You needed to add a ")" at the end. Range("J" & Count + 2).Formula = "=IF(I" & Count + 2 & "=""00/00/0000"",0,IF(I" & Count + 2 & "-H" & Count + 2 & "1,1,0))" Hope this helps! If so, let me know, click 'YES" below. -- Cheers, Ryan "Luke" wrote: I wrote a macro to reformat a report. As it goes from row to row rearranging the data from the report, there are some cells where I need the code to enter a formula into the cell. However, when it hits that part I keep getting error 1004 - application or user-defined error. Here is the portion of the code that gives me fits: Range("H" & Count + 2).Value = Range("F" & Count + 6).Value Range("I" & Count + 2).Value = "" Range("J" & Count + 2).Formula = "=IF(I" & Count + 2 & "=""00/00/0000"",0,IF(I" & Count + 2 & "-H" & Count + 2 & _ "1,1,0)" I get the error when it hits the 'Range("J"' line. For referrence, the value placed into column H is a date and Count is Dim'd as Long. I'm not worried that the result of the formula (that I'm trying to put in column J) will give an error, I just want the formula there. I've even tried changing the code so that it always puts "00/00/0000" in column I, but it didn't work. |
All times are GMT +1. The time now is 03:00 PM. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com