Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 334
Default If function in Macro

Hi,

This is the if statement in Excel,

=IF(NOW()+7H5,$J5,"").

This is how I have it in the macro,

Range("R5").Select
ActiveCell.FormulaR1C1 = "=if(now()+7RC[-10],$RC[-8],"")"

But I get and object defined error.

Is my problem with R1C1 reference style or something else?

Thanks
rick
When I run the macro I get
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,101
Default If function in Macro

Range("R5").value = "=IF(NOW()+7H5,$J5,'')."


"Rick" wrote:

Hi,

This is the if statement in Excel,

=IF(NOW()+7H5,$J5,"").

This is how I have it in the macro,

Range("R5").Select
ActiveCell.FormulaR1C1 = "=if(now()+7RC[-10],$RC[-8],"")"

But I get and object defined error.

Is my problem with R1C1 reference style or something else?

Thanks
rick
When I run the macro I get

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,058
Default If function in Macro

dq is the double quote character:

Sub rick()
dq = Chr(34)
s = "=IF(NOW()+7H5,$J5," & dq & dq & ")"
Range("R5").Formula = s
End Sub

--
Gary''s Student - gsnu200798


"Rick" wrote:

Hi,

This is the if statement in Excel,

=IF(NOW()+7H5,$J5,"").

This is how I have it in the macro,

Range("R5").Select
ActiveCell.FormulaR1C1 = "=if(now()+7RC[-10],$RC[-8],"")"

But I get and object defined error.

Is my problem with R1C1 reference style or something else?

Thanks
rick
When I run the macro I get

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 334
Default If function in Macro

How would I then copy this down to the bottom of the selection?

I was thinking that once the formula was done I could copy and paste but
with Range..., how this then work?

"Mike" wrote:

Range("R5").value = "=IF(NOW()+7H5,$J5,'')."


"Rick" wrote:

Hi,

This is the if statement in Excel,

=IF(NOW()+7H5,$J5,"").

This is how I have it in the macro,

Range("R5").Select
ActiveCell.FormulaR1C1 = "=if(now()+7RC[-10],$RC[-8],"")"

But I get and object defined error.

Is my problem with R1C1 reference style or something else?

Thanks
rick
When I run the macro I get

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,101
Default If function in Macro

Range("D1").Value = "=IF(NOW()+7H5,$J5,"""")"

"Mike" wrote:

Range("R5").value = "=IF(NOW()+7H5,$J5,'')."


"Rick" wrote:

Hi,

This is the if statement in Excel,

=IF(NOW()+7H5,$J5,"").

This is how I have it in the macro,

Range("R5").Select
ActiveCell.FormulaR1C1 = "=if(now()+7RC[-10],$RC[-8],"")"

But I get and object defined error.

Is my problem with R1C1 reference style or something else?

Thanks
rick
When I run the macro I get



  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,101
Default If function in Macro

Is the bottom of the selection always the same?

"Rick" wrote:

How would I then copy this down to the bottom of the selection?

I was thinking that once the formula was done I could copy and paste but
with Range..., how this then work?

"Mike" wrote:

Range("R5").value = "=IF(NOW()+7H5,$J5,'')."


"Rick" wrote:

Hi,

This is the if statement in Excel,

=IF(NOW()+7H5,$J5,"").

This is how I have it in the macro,

Range("R5").Select
ActiveCell.FormulaR1C1 = "=if(now()+7RC[-10],$RC[-8],"")"

But I get and object defined error.

Is my problem with R1C1 reference style or something else?

Thanks
rick
When I run the macro I get

  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 334
Default If function in Macro

What is the dq referring to?

"Gary''s Student" wrote:

dq is the double quote character:

Sub rick()
dq = Chr(34)
s = "=IF(NOW()+7H5,$J5," & dq & dq & ")"
Range("R5").Formula = s
End Sub

--
Gary''s Student - gsnu200798


"Rick" wrote:

Hi,

This is the if statement in Excel,

=IF(NOW()+7H5,$J5,"").

This is how I have it in the macro,

Range("R5").Select
ActiveCell.FormulaR1C1 = "=if(now()+7RC[-10],$RC[-8],"")"

But I get and object defined error.

Is my problem with R1C1 reference style or something else?

Thanks
rick
When I run the macro I get

  #8   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,101
Default If function in Macro

tihs will goto row 10
For i = 5 To 10
Range("R" & i).Value = _
"=IF(NOW()+7H" & i & ",$J" & i & ","""")"
Next

"Rick" wrote:

How would I then copy this down to the bottom of the selection?

I was thinking that once the formula was done I could copy and paste but
with Range..., how this then work?

"Mike" wrote:

Range("R5").value = "=IF(NOW()+7H5,$J5,'')."


"Rick" wrote:

Hi,

This is the if statement in Excel,

=IF(NOW()+7H5,$J5,"").

This is how I have it in the macro,

Range("R5").Select
ActiveCell.FormulaR1C1 = "=if(now()+7RC[-10],$RC[-8],"")"

But I get and object defined error.

Is my problem with R1C1 reference style or something else?

Thanks
rick
When I run the macro I get

  #9   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 334
Default If function in Macro

No, but I have a formula to indicate how far down to copy.

"Mike" wrote:

Is the bottom of the selection always the same?

"Rick" wrote:

How would I then copy this down to the bottom of the selection?

I was thinking that once the formula was done I could copy and paste but
with Range..., how this then work?

"Mike" wrote:

Range("R5").value = "=IF(NOW()+7H5,$J5,'')."


"Rick" wrote:

Hi,

This is the if statement in Excel,

=IF(NOW()+7H5,$J5,"").

This is how I have it in the macro,

Range("R5").Select
ActiveCell.FormulaR1C1 = "=if(now()+7RC[-10],$RC[-8],"")"

But I get and object defined error.

Is my problem with R1C1 reference style or something else?

Thanks
rick
When I run the macro I get

  #10   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 334
Default If function in Macro

Thanks this works well, in that it puts the formula into the cell but it
isn't showing the answer.

Basically it is saying if today's date plus 7 days is greater than the date
in H5 then show the value in J5, Well the date in H5 is a week ago so it
should be showing the J5 value but there is nothing showing in the cells,
even after I calculate manually.

Thanks
Rick

"Mike" wrote:

tihs will goto row 10
For i = 5 To 10
Range("R" & i).Value = _
"=IF(NOW()+7H" & i & ",$J" & i & ","""")"
Next

"Rick" wrote:

How would I then copy this down to the bottom of the selection?

I was thinking that once the formula was done I could copy and paste but
with Range..., how this then work?

"Mike" wrote:

Range("R5").value = "=IF(NOW()+7H5,$J5,'')."


"Rick" wrote:

Hi,

This is the if statement in Excel,

=IF(NOW()+7H5,$J5,"").

This is how I have it in the macro,

Range("R5").Select
ActiveCell.FormulaR1C1 = "=if(now()+7RC[-10],$RC[-8],"")"

But I get and object defined error.

Is my problem with R1C1 reference style or something else?

Thanks
rick
When I run the macro I get



  #11   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,058
Default If function in Macro

dq is a string variable. It contains the double quote character.
--
Gary''s Student - gsnu200798
  #12   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,355
Default If function in Macro

Here's an alternate way to do it

Sub Test()
Dim aWS As Worksheet
Dim myRange As Range
Dim lRow As Long

Set aWS = ActiveSheet
Set myRange = aWS.Range("H5") '<~~~~this is the starting range
lRow = myRange.End(xlDown).Row

'Defining range in column H to use in formula
Set myRange = myRange.Resize(lRow - myRange.Row + 1, 1)

'Defining range in r for formula

Set myRange = myRange.Offset(0, 10)
myRange.FormulaR1C1 = "=IF(NOW()+7RC[-10],RC10,"""")"
'Alternate???
'myRange.FormulaR1C1 = "=IF(NOW()+7=RC[-10],RC10,"""")"
End Sub

I think in the formula, you may need to change it to include an = sign.
--
HTH,
Barb Reinhardt



"Rick" wrote:

Thanks this works well, in that it puts the formula into the cell but it
isn't showing the answer.

Basically it is saying if today's date plus 7 days is greater than the date
in H5 then show the value in J5, Well the date in H5 is a week ago so it
should be showing the J5 value but there is nothing showing in the cells,
even after I calculate manually.

Thanks
Rick

"Mike" wrote:

tihs will goto row 10
For i = 5 To 10
Range("R" & i).Value = _
"=IF(NOW()+7H" & i & ",$J" & i & ","""")"
Next

"Rick" wrote:

How would I then copy this down to the bottom of the selection?

I was thinking that once the formula was done I could copy and paste but
with Range..., how this then work?

"Mike" wrote:

Range("R5").value = "=IF(NOW()+7H5,$J5,'')."


"Rick" wrote:

Hi,

This is the if statement in Excel,

=IF(NOW()+7H5,$J5,"").

This is how I have it in the macro,

Range("R5").Select
ActiveCell.FormulaR1C1 = "=if(now()+7RC[-10],$RC[-8],"")"

But I get and object defined error.

Is my problem with R1C1 reference style or something else?

Thanks
rick
When I run the macro I get

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
Sub Macro vrs Function Macro Auto Start Pat Excel Discussion (Misc queries) 7 June 6th 07 09:53 PM
macro or function ssrvant Excel Programming 0 November 7th 06 04:45 PM
Macro run from if then function ram Excel Programming 2 May 24th 06 02:53 PM
how to count/sum by function/macro to get the number of record to do copy/paste in macro tango Excel Programming 1 October 15th 04 01:16 PM
Run macro from IF function Stu[_23_] Excel Programming 1 September 29th 03 12:30 PM


All times are GMT +1. The time now is 05:10 AM.

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"