#1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 169
Default Formulae

I have the following formula in j2

=IF(AND(B2="Amount",C2<0),C2,IF(AND(B2="Amount",C 2=0,H2<0),"DIRECT",9))

Hi, Im trying to incorporate the above formula into a macro (below) but am
having some problems with the elses and nesting.

For i = 1 to 100

f Cells(i, 2) = "Amount" Then
If Cells(i, 3) < 0 Then
Cells(i, 10) = Cells(i, 3)
Else
If .......


End If
End If
Next
End Sub


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,163
Default Formulae

If Cells(i,2)="Amount" Then
If Cells(i,3)<0 Then
Cells(i,10)= Cells(i,3)
Else
If Cells(i,8)<0 Then Cells(i,10) = "DIRECT" Else Cells(i,10) = 9
End If
End If

"teresa" wrote:

I have the following formula in j2

=IF(AND(B2="Amount",C2<0),C2,IF(AND(B2="Amount",C 2=0,H2<0),"DIRECT",9))

Hi, Im trying to incorporate the above formula into a macro (below) but am
having some problems with the elses and nesting.

For i = 1 to 100

f Cells(i, 2) = "Amount" Then
If Cells(i, 3) < 0 Then
Cells(i, 10) = Cells(i, 3)
Else
If .......


End If
End If
Next
End Sub


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 694
Default Formulae

Hi Teresa,
A much faster way that looping through all the cells is to:
- Write the formula in the cells in a single statement:
Range("A2:A101").Formula = "=IF(.....)"
This writes the formula in the whole range A2:A101.
The formula expression should be made based on the first cell in the
Range (here, A2); Excel will then adjust automatically.
- Then Copy /Paste As Value range A2:A101

So in your example:
Sub test()

'Put formula in cells in a single statement
Range("A2:A101").Formula = _
"=IF(AND(B2=""Amount"",C2<0),C2," & _
"IF(AND(B2=""Amount"",C2=0,H2<0),""DIRECT"",9 ))"

'Copy/paste As Value
Range("A2:A101").Copy
Range("A2:A101").PasteSpecial xlPasteValues
Application.CutCopyMode = False

End Sub

I hope this helps,
Sebastien

"teresa" wrote:

I have the following formula in j2

=IF(AND(B2="Amount",C2<0),C2,IF(AND(B2="Amount",C 2=0,H2<0),"DIRECT",9))

Hi, Im trying to incorporate the above formula into a macro (below) but am
having some problems with the elses and nesting.

For i = 1 to 100

f Cells(i, 2) = "Amount" Then
If Cells(i, 3) < 0 Then
Cells(i, 10) = Cells(i, 3)
Else
If .......


End If
End If
Next
End Sub


  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 169
Default Formulae

Thank You both - very helpful

"sebastienm" wrote:

Hi Teresa,
A much faster way that looping through all the cells is to:
- Write the formula in the cells in a single statement:
Range("A2:A101").Formula = "=IF(.....)"
This writes the formula in the whole range A2:A101.
The formula expression should be made based on the first cell in the
Range (here, A2); Excel will then adjust automatically.
- Then Copy /Paste As Value range A2:A101

So in your example:
Sub test()

'Put formula in cells in a single statement
Range("A2:A101").Formula = _
"=IF(AND(B2=""Amount"",C2<0),C2," & _
"IF(AND(B2=""Amount"",C2=0,H2<0),""DIRECT"",9 ))"

'Copy/paste As Value
Range("A2:A101").Copy
Range("A2:A101").PasteSpecial xlPasteValues
Application.CutCopyMode = False

End Sub

I hope this helps,
Sebastien

"teresa" wrote:

I have the following formula in j2

=IF(AND(B2="Amount",C2<0),C2,IF(AND(B2="Amount",C 2=0,H2<0),"DIRECT",9))

Hi, Im trying to incorporate the above formula into a macro (below) but am
having some problems with the elses and nesting.

For i = 1 to 100

f Cells(i, 2) = "Amount" Then
If Cells(i, 3) < 0 Then
Cells(i, 10) = Cells(i, 3)
Else
If .......


End If
End If
Next
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
Formulae Help KevL Excel Worksheet Functions 6 February 11th 10 08:47 PM
help with a formulae Nemo Excel Discussion (Misc queries) 2 January 29th 10 07:57 AM
Formulae: Paste value formulae after doing an average operation Lim Excel Discussion (Misc queries) 4 April 20th 08 07:31 PM
Formulae k f h Excel Worksheet Functions 6 July 19th 05 09:58 AM
Searching TEXT in formulae, rather than results of formulae AndyE Excel Worksheet Functions 1 July 15th 05 10:57 AM


All times are GMT +1. The time now is 05:45 PM.

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

About Us

"It's about Microsoft Excel"