Nested IF statements... Please Help

Status
Not open for further replies.

jharvey_22

New Member
Joined
Jun 10, 2011
Messages
8
Here is my code:

Option Explicit
Dim i As Long
Dim j As Long
Dim x As Long
Sub Report4()
'Gather Income Statement information from comparison tab and determine if value is >0. If data set contains
'this value, we will record that in the report. Because we know i & j, we know where the value is located in
'the comparison tab. Using this information, we can locate the other information we want for the report.
With Application
.ScreenUpdating = False
.EnableEvents = False
.Calculation = xlCalculationManual
End With
x = 0
For i = 0 To 202
For j = 0 To 58
If IsError(Worksheets("Comparison").Range("D19").Offset(i, j)) Then
Else
If (Worksheets("Comparison").Range("InitialQuarter") = "1") And (Worksheets("Comparison").Range("CurrentQuarter") = "2") Then
If (Worksheets("Comparison").Range("A19").Offset(i, 0)) = "E" Or (Worksheets("Comparison").Range("A19").Offset(i, 0)) = "I" Then
If (Worksheets("Comparison").Range("D19").Offset(i, j)) < 0.5 Or (Worksheets("Comparison").Range("D19").Offset(i, j)) > 1.5 Then
x = x + 1
Range("percentagechange4").Offset(x - 1, 0) = Worksheets("Comparison").Range("D19:BI220").Offset(i, j).Value 'Value of the % change is reported here
Range("hfmnumber4start").Offset(x - 1, 0) = Worksheets("Comparison").Range("B19").Offset(i, 0) 'since we know the row where the error is, we can look up the HFM # in that row
Range("hfmaccount4start").Offset(x - 1, 0) = Worksheets("comparison").Range("C19").Offset(i, 0) 'since we know the row where the error is, we can look up the HFM account in that row
Range("location4start").Offset(x - 1, 0) = Worksheets("comparison").Range("D15").Offset(0, j) 'since we know the column where the error is, we can look up the entity in that row
End If
End If
ElseIf (Worksheets("Comparison").Range("InitialQuarter") = "2") And (Worksheets("Comparison").Range("CurrentQuarter") = "3") Then
If (Worksheets("Comparison").Range("A19").Offset(i, 0)) = "E" Or (Worksheets("Comparison").Range("A19").Offset(i, 0)) = "I" Then
If (Worksheets("Comparison").Range("D19").Offset(i, j)) < 0 Or (Worksheets("Comparison").Range("D19").Offset(i, j)) > 1 Then
x = x + 1
Range("percentagechange4").Offset(x - 1, 0) = Worksheets("Comparison").Range("D19:BI220").Offset(i, j).Value 'Value of the % change is reported here
Range("hfmnumber4start").Offset(x - 1, 0) = Worksheets("Comparison").Range("B19").Offset(i, 0) 'since we know the row where the error is, we can look up the HFM # in that row
Range("hfmaccount4start").Offset(x - 1, 0) = Worksheets("comparison").Range("C19").Offset(i, 0) 'since we know the row where the error is, we can look up the HFM account in that row
Range("location4start").Offset(x - 1, 0) = Worksheets("comparison").Range("D15").Offset(0, j) 'since we know the column where the error is, we can look up the entity in that row
End If
End If
ElseIf (Worksheets("Comparison").Range("InitialQuarter") = "3") And (Worksheets("Comparison").Range("CurrentQuarter") = "4") Then
If (Worksheets("Comparison").Range("A19").Offset(i, 0)) = "E" Or (Worksheets("Comparison").Range("A19").Offset(i, 0)) = "I" Then
If (Worksheets("Comparison").Range("D19").Offset(i, j)) < -0.1667 Or (Worksheets("Comparison").Range("D19").Offset(i, j)) > 0.8334 Then
x = x + 1
Range("percentagechange4").Offset(x - 1, 0) = Worksheets("Comparison").Range("D19:BI220").Offset(i, j).Value 'Value of the % change is reported here
Range("hfmnumber4start").Offset(x - 1, 0) = Worksheets("Comparison").Range("B19").Offset(i, 0) 'since we know the row where the error is, we can look up the HFM # in that row
Range("hfmaccount4start").Offset(x - 1, 0) = Worksheets("comparison").Range("C19").Offset(i, 0) 'since we know the row where the error is, we can look up the HFM account in that row
Range("location4start").Offset(x - 1, 0) = Worksheets("comparison").Range("D15").Offset(0, j) 'since we know the column where the error is, we can look up the entity in that row
End If
End If
End If
End If
Next j
Next i
With Application
.ScreenUpdating = True
.EnableEvents = True
.Calculation = xlCalculationAutomatic
End With
End Sub


Why does this code not work? I have three scenerios: when its quarter 1 &2, when its quarter 2 &3, and when its quarter 3&4. I need to do different things with each of these scenerios. If you could help me figure this out and get the code to work. I think the code is pretty easy to follow. Thanks for your help!
 

Excel Facts

Links? Where??
If Excel says you have links but you can't find them, go to Formulas, Name Manager. Look for old links to dead workbooks & delete.
Status
Not open for further replies.

Forum statistics

Threads
1,224,586
Messages
6,179,728
Members
452,939
Latest member
WCrawford

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top