LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
Tim Tim is offline
external usenet poster
 
Posts: 408
Default loop with many if

Hi ALL,


Sub addnumbers()

Application.ScreenUpdating = False
Application.Calculation = xlManual
Dim i As Integer, j As Integer
Dim numTrades As Integer, Amt As Double, StartDate As Date


numTrades = Range("X1")



i = 1
For j = 1 To numTrades
If Cells(j + 3, 23) < "" And Cells(j + 3, 27) = "" Then

Cells(j + 3, 2) = Cells(i + 3, 31)

i = i + 1

End If
Next j
Application.Calculation = xlAutomatic

End Sub


I want to add additional IF STATEMENTS to the above macro:

After the line : If Cells(j + 3, 23) < "" And Cells(j + 3, 27) = "" Then
I need to add the following 2 if conditions:
1. If Cells(j + 3, 25) = "S"
Cells(j + 3, 2) = Cells(i + 3, 31)

and 2. If Cells(j + 3, 25) = "L"
Cells(j + 3, 4) = Cells(i + 3, 31)

The final code should be something like:
i = 1
For j = 1 To numTrades ' go thru all trades
If Cells(j + 3, 23) < "" And Cells(j + 3, 27) = "" Then
If Cells(j + 3, 25) = "S" Then
Cells(j + 3, 2) = Cells(i + 3, 31)
If Cells(j + 3, 25) = "L" Then
Cells(j + 3, 4) = Cells(i + 3, 31)
i = i + 1
End If
End If
End If
Next j

but it doesnt work. Tried also some Elseif statements with no success.
Any Help is Highly Appreciated.


 
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
returning back to loop check condition without completing the loop ashish128 Excel Programming 13 April 3rd 08 12:53 PM
Loop to Filter, Name Sheets. If Blank, Exit Loop ryguy7272 Excel Programming 3 February 5th 08 03:41 PM
Naming Worksheets - Loop within a loop issue klysell Excel Programming 5 March 29th 07 05:48 AM
Advancing outer Loop Based on criteria of inner loop ExcelMonkey Excel Programming 1 August 15th 05 05:23 PM
Problem adding charts using Do-Loop Until loop Chris Bromley[_2_] Excel Programming 2 May 23rd 05 01:31 PM


All times are GMT +1. The time now is 03:43 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"