Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
Run-time error 1004
The code that I am trying to use is very simple.
I would like to replicare automatically a formula along many cells, one yes and one no along a given range. So I tried to build a macro: sub a () for i 4 to 400 step 2 range(i).formula="=if(a2<b2;a2;b2) next i end sub The macro doesn't work even without the for-next cicle. On the contrary, the formula =if(a2<b2;a2;b2) works as expected when placed in a cell of the worksheet inside which I want to run the macro. What am I doing wrong? Thank you for your help, Riccardo |
#2
Posted to microsoft.public.excel.programming
|
|||
|
|||
Run-time error 1004
Not sure that the following is really the answer you require.
Firstly my example uses the comma (,) as a delimiter in the formula so I am not sure if the semi colon (;) is causing you a problem or perhaps you use that in your country of origin. When you want to use a formula with relative addressing then you need to code the formula in the first cell then the next line of code copies that cell to the remaining cells something like the following. Range("A3").Formula = "=IF(A2<B2,A2,B2)" Range("A3").Copy Destination:=Range("A3:AH3") If this does not answer your question then perhaps you can supply a little mor explanation with an example of your data. Regards, OssieMac |
#3
Posted to microsoft.public.excel.programming
|
|||
|
|||
Run-time error 1004
VBA is USA centric.
Use commas instead of semicolons. But I'm confused about what Range(i) is. sub a () for i = 4 to 400 step 2 range(i).formula="=if(a2<b2,a2,b2)" next i end sub Riccardo Pucher Prencis wrote: The code that I am trying to use is very simple. I would like to replicare automatically a formula along many cells, one yes and one no along a given range. So I tried to build a macro: sub a () for i 4 to 400 step 2 range(i).formula="=if(a2<b2;a2;b2) next i end sub The macro doesn't work even without the for-next cicle. On the contrary, the formula =if(a2<b2;a2;b2) works as expected when placed in a cell of the worksheet inside which I want to run the macro. What am I doing wrong? Thank you for your help, Riccardo -- Dave Peterson |
#4
Posted to microsoft.public.excel.programming
|
|||
|
|||
Run-time error 1004
To take what Dave Peterson a step further: if you are using i as a row
counter, then you probably need to change the line that sets up the formula from Range(i).Formula = ... to Range("C" & i).Formula = ... assuming C is the column where you want to put the formula. "Riccardo Pucher Prencis" wrote: The code that I am trying to use is very simple. I would like to replicare automatically a formula along many cells, one yes and one no along a given range. So I tried to build a macro: sub a () for i 4 to 400 step 2 range(i).formula="=if(a2<b2;a2;b2) next i end sub The macro doesn't work even without the for-next cicle. On the contrary, the formula =if(a2<b2;a2;b2) works as expected when placed in a cell of the worksheet inside which I want to run the macro. What am I doing wrong? Thank you for your help, Riccardo |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
run time error 1004 general odbc error excel 2003 vba | Excel Programming | |||
Run Time Error 1004: Application or Object Defined Error | Excel Programming | |||
Run Time 1004 Error: Application or Object Difine Error | Excel Programming | |||
run-time error '1004': Application-defined or object-deifined error | Excel Programming | |||
Run time error '1004': Generaol ODBC error | Excel Programming |