Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,069
Default Simple IF give me nothing?

Hi the following code runs just fine and gives me All my data...
Sub backtest()
Application.Calculation = xlCalculationManual
counter = 0
lastcell = ThisWorkbook.Sheets("backtest").Range("a4000").End (xlUp).Address
nxtday = ThisWorkbook.Sheets("P&L").Range("a4000").End(xlUp ).Row + 1
For Each i In ThisWorkbook.Sheets("backtest").Range("a4", lastcell)
rw = i.Row

Sheets("P&L").Range("a" & nxtday + counter) =
Sheets("backtest").Range("b" & rw)
Sheets("P&L").Range("b" & nxtday + counter) =
Sheets("backtest").Range("H" & rw)

counter = counter + 1
Next
Application.Calculation = xlCalculationAutomatic
End Sub


When I add the IF statement in the middle it returns nothing...
Sub backtest()
Application.Calculation = xlCalculationManual
counter = 0
lastcell = ThisWorkbook.Sheets("backtest").Range("a4000").End (xlUp).Address
nxtday = ThisWorkbook.Sheets("P&L").Range("a4000").End(xlUp ).Row + 1
For Each i In ThisWorkbook.Sheets("backtest").Range("a4", lastcell)
rw = i.Row
If Sheets("backtest").Range("H" & rw) < 0 Then
Sheets("P&L").Range("a" & nxtday + counter) =
Sheets("backtest").Range("b" & rw)
Sheets("P&L").Range("b" & nxtday + counter) =
Sheets("backtest").Range("H" & rw)
End If
counter = counter + 1
Next
Application.Calculation = xlCalculationAutomatic
End Sub

Column H has 0 and non zero values and I only want the non 0s

Also of note... If I run the code with the IF statement, then delete it the
code does not work and i have to close the file and reopen it... something
wrong in calculation enablement? I don't recieve any errors

Thanks
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 126
Default Simple IF give me nothing?

try ...
If Sheets("Sheet2").Range("H" & rw).Value < 0 Then
AND
I think you want the counter statement (counter = counter + 1) BEFORE the
'End If' statement.
--
Hope this helps.
If it does, please click the Yes button.
Thanks in advance for your feedback.
Gary Brown



"John" wrote:

Hi the following code runs just fine and gives me All my data...
Sub backtest()
Application.Calculation = xlCalculationManual
counter = 0
lastcell = ThisWorkbook.Sheets("backtest").Range("a4000").End (xlUp).Address
nxtday = ThisWorkbook.Sheets("P&L").Range("a4000").End(xlUp ).Row + 1
For Each i In ThisWorkbook.Sheets("backtest").Range("a4", lastcell)
rw = i.Row

Sheets("P&L").Range("a" & nxtday + counter) =
Sheets("backtest").Range("b" & rw)
Sheets("P&L").Range("b" & nxtday + counter) =
Sheets("backtest").Range("H" & rw)

counter = counter + 1
Next
Application.Calculation = xlCalculationAutomatic
End Sub


When I add the IF statement in the middle it returns nothing...
Sub backtest()
Application.Calculation = xlCalculationManual
counter = 0
lastcell = ThisWorkbook.Sheets("backtest").Range("a4000").End (xlUp).Address
nxtday = ThisWorkbook.Sheets("P&L").Range("a4000").End(xlUp ).Row + 1
For Each i In ThisWorkbook.Sheets("backtest").Range("a4", lastcell)
rw = i.Row
If Sheets("backtest").Range("H" & rw) < 0 Then
Sheets("P&L").Range("a" & nxtday + counter) =
Sheets("backtest").Range("b" & rw)
Sheets("P&L").Range("b" & nxtday + counter) =
Sheets("backtest").Range("H" & rw)
End If
counter = counter + 1
Next
Application.Calculation = xlCalculationAutomatic
End Sub

Column H has 0 and non zero values and I only want the non 0s

Also of note... If I run the code with the IF statement, then delete it the
code does not work and i have to close the file and reopen it... something
wrong in calculation enablement? I don't recieve any errors

Thanks

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,069
Default Simple IF give me nothing?

If Sheets("Sheet5").Range("H" & rw).Value < 0 Then

gives me a subscript out of range

If Sheets("backtest").Range("H" & rw).Value < 0 Then

pulled two of the values one time and 4 the next, and then none.... I think
my sheet is too big and is corrupted

"Gary Brown" wrote:

try ...
If Sheets("Sheet2").Range("H" & rw).Value < 0 Then
AND
I think you want the counter statement (counter = counter + 1) BEFORE the
'End If' statement.
--
Hope this helps.
If it does, please click the Yes button.
Thanks in advance for your feedback.
Gary Brown



"John" wrote:

Hi the following code runs just fine and gives me All my data...
Sub backtest()
Application.Calculation = xlCalculationManual
counter = 0
lastcell = ThisWorkbook.Sheets("backtest").Range("a4000").End (xlUp).Address
nxtday = ThisWorkbook.Sheets("P&L").Range("a4000").End(xlUp ).Row + 1
For Each i In ThisWorkbook.Sheets("backtest").Range("a4", lastcell)
rw = i.Row

Sheets("P&L").Range("a" & nxtday + counter) =
Sheets("backtest").Range("b" & rw)
Sheets("P&L").Range("b" & nxtday + counter) =
Sheets("backtest").Range("H" & rw)

counter = counter + 1
Next
Application.Calculation = xlCalculationAutomatic
End Sub


When I add the IF statement in the middle it returns nothing...
Sub backtest()
Application.Calculation = xlCalculationManual
counter = 0
lastcell = ThisWorkbook.Sheets("backtest").Range("a4000").End (xlUp).Address
nxtday = ThisWorkbook.Sheets("P&L").Range("a4000").End(xlUp ).Row + 1
For Each i In ThisWorkbook.Sheets("backtest").Range("a4", lastcell)
rw = i.Row
If Sheets("backtest").Range("H" & rw) < 0 Then
Sheets("P&L").Range("a" & nxtday + counter) =
Sheets("backtest").Range("b" & rw)
Sheets("P&L").Range("b" & nxtday + counter) =
Sheets("backtest").Range("H" & rw)
End If
counter = counter + 1
Next
Application.Calculation = xlCalculationAutomatic
End Sub

Column H has 0 and non zero values and I only want the non 0s

Also of note... If I run the code with the IF statement, then delete it the
code does not work and i have to close the file and reopen it... something
wrong in calculation enablement? I don't recieve any errors

Thanks

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
IF formula-simple question; simple operator Rich D Excel Discussion (Misc queries) 4 December 6th 07 03:36 PM
Can someone give me "simple" instruction for creating home budget Georgiagirl Excel Discussion (Misc queries) 1 August 24th 06 11:59 PM
Give RELEVANT responses to questions. DO NOT give usless list pmartin Excel Worksheet Functions 2 July 6th 06 06:08 PM
Simple Simple Excel usage question BookerW Excel Discussion (Misc queries) 1 June 23rd 05 10:06 PM
Can someone give me a simple macro to sort a column? Dan Orth Excel Programming 4 December 11th 04 06:39 PM


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