sourabh_ajmera
New Member
- Joined
- Jul 17, 2014
- Messages
- 36
Hello Everybody,
I'll try my best to explain this complex situation. There is data in column A and Column D. Data in column A is account no and data in Column D is some % value.
Each account can have multiple % (please refer table below for example)
Now I am trying to write a code to see if the next cell in Column A is empty, if empty than we know that we have to average the % values in Column D to get the average for the account no. This average value is stored in Column E.
E.g: So for account 12345 average % value from column D shoud be 0.5% only displayed in Column E. But, for 56789 the average should be (1.31+2.67)/2 and so on..
[TABLE="class: outer_border, width: 600"]
<tbody>[TR]
[TD]Column A (Account no)[/TD]
[TD]Column B...Column C (Random data)[/TD]
[TD]Column D (% values)[/TD]
[TD]Column E (Average %)[/TD]
[/TR]
[TR]
[TD]12345[/TD]
[TD]xyz[/TD]
[TD]0.5%[/TD]
[TD]0.5%[/TD]
[/TR]
[TR]
[TD]56789[/TD]
[TD]fgyhd[/TD]
[TD]1.31%[/TD]
[TD]1.99%[/TD]
[/TR]
[TR]
[TD][/TD]
[TD][/TD]
[TD]2.67%[/TD]
[TD][/TD]
[/TR]
[TR]
[TD]84289[/TD]
[TD]dghdfg[/TD]
[TD]5.4%[/TD]
[TD]2.33%[/TD]
[/TR]
[TR]
[TD][/TD]
[TD][/TD]
[TD]0.034%[/TD]
[TD][/TD]
[/TR]
[TR]
[TD][/TD]
[TD][/TD]
[TD]1.56%[/TD]
[TD][/TD]
[/TR]
[TR]
[TD]8936734[/TD]
[TD]fjdfsgsjkf[/TD]
[TD]4.9%[/TD]
[TD]4.9%[/TD]
[/TR]
</tbody>[/TABLE]
Here's the code that I tried but eventually fails at the IsEmpty condition. Please help me for this as I am confused and out of ideas.
Please let me know if I can help further clearing your doubts. Thanks in advance.
I'll try my best to explain this complex situation. There is data in column A and Column D. Data in column A is account no and data in Column D is some % value.
Each account can have multiple % (please refer table below for example)
Now I am trying to write a code to see if the next cell in Column A is empty, if empty than we know that we have to average the % values in Column D to get the average for the account no. This average value is stored in Column E.
E.g: So for account 12345 average % value from column D shoud be 0.5% only displayed in Column E. But, for 56789 the average should be (1.31+2.67)/2 and so on..
[TABLE="class: outer_border, width: 600"]
<tbody>[TR]
[TD]Column A (Account no)[/TD]
[TD]Column B...Column C (Random data)[/TD]
[TD]Column D (% values)[/TD]
[TD]Column E (Average %)[/TD]
[/TR]
[TR]
[TD]12345[/TD]
[TD]xyz[/TD]
[TD]0.5%[/TD]
[TD]0.5%[/TD]
[/TR]
[TR]
[TD]56789[/TD]
[TD]fgyhd[/TD]
[TD]1.31%[/TD]
[TD]1.99%[/TD]
[/TR]
[TR]
[TD][/TD]
[TD][/TD]
[TD]2.67%[/TD]
[TD][/TD]
[/TR]
[TR]
[TD]84289[/TD]
[TD]dghdfg[/TD]
[TD]5.4%[/TD]
[TD]2.33%[/TD]
[/TR]
[TR]
[TD][/TD]
[TD][/TD]
[TD]0.034%[/TD]
[TD][/TD]
[/TR]
[TR]
[TD][/TD]
[TD][/TD]
[TD]1.56%[/TD]
[TD][/TD]
[/TR]
[TR]
[TD]8936734[/TD]
[TD]fjdfsgsjkf[/TD]
[TD]4.9%[/TD]
[TD]4.9%[/TD]
[/TR]
</tbody>[/TABLE]
Here's the code that I tried but eventually fails at the IsEmpty condition. Please help me for this as I am confused and out of ideas.
Please let me know if I can help further clearing your doubts. Thanks in advance.
Rich (BB code):
Sub Test()
Dim AvgNIM As Double, AvgNIM1 As Double, AvgNIM2 As Double, FindAvg As Double
Dim VerifyEmpty As Integer
For VerifyEmpty = 2 To 100
Sheets("Rate Calculator").Select
If (Range("A" & VerifyEmpty).Value = Range("B" & VerifyEmpty).Value) Then
If Not Range("A" & VerifyEmpty).Value = "" Then
AvgNIM = Range("D" & VerifyEmpty).Value
End If
If Range("A" & VerifyEmpty + 1).Value = "" Then
AvgNIM1 = Range("D" & VerifyEmpty + 1).Value
If Range("A" & VerifyEmpty + 2).Value = "" Then
AvgNIM2 = Range("D" & VerifyEmpty + 2).Value
End If
End If
If Not IsEmpty(AvgNIM) And Not IsEmpty(AvgNIM1) And Not IsEmpty(AvgNIM2) Then <---- Error (it executes this 'If' block even if the value is empty)
FindAvg = (AvgNIM + AvgNIM1 + AvgNIM2) / 3
Range("E" & VerifyEmpty).Value = FindAvg
ElseIf Not AvgNIM = "" And Not AvgNIM1 = "" Then
FindAvg = (AvgNIM + AvgNIM1) / 2
Range("E" & VerifyEmpty).Value = FindAvg
'End If
Else
Range("E" & VerifyEmpty).Value = AvgNIM
End If
End If
Next VerifyEmpty
End Sub