jharvey_22
New Member
- Joined
- Jun 10, 2011
- Messages
- 8
Here is my code that I'm working with:
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!
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
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!