View Single Post
  #15   Report Post  
Posted to microsoft.public.excel.programming
Paige Paige is offline
external usenet poster
 
Posts: 270
Default 'If' Statement - Must be a Better Way to Do This!

Thanks Gordon for responding. I'm trying all the variations suggested and
they all work, each in a different way of course, and I'm learning alot from
all the suggestions. Appreciate your assistance - have a great day!

"Gordon Rainsford" wrote:

How about Select Case?

Gordon Rainsford

Paige wrote:

In my spreadsheet, the user is asked to enter the # of rates in cell C17;
they can enter up to 10. I want to check to see if they've answered all 4
questions for each rate (each set of 4 questions (for each rate) is
non-contiguous with the next set of questions for another rate). A sample
of my current code is below. The problem is that there are up to 10 rates
for 18 different categories. By the time I finish doing all the code, it
will be huge. Surely there is a better way to accomplish this; I'm just an
intermediate VBA skill level (if that), and any help would be appreciated to
do this more efficiently. Thanks for any assistance...


Const BlankRates As String = "You've got some blanks, please complete all
the blanks."

Sub CheckforErrors56()
If Range("C17") = 1 Then
If Application.CountBlank(Range("C20:C23")) = 1 Then
MsgBox BlankRates
Else
Call TrimIt1
End If
Else
If Range("C17") = 2 Then
If Application.CountBlank(Range("C20:C23")) = 1 Or _
Application.CountBlank(Range("C26:C29")) = 1 Then
MsgBox BlankRates
Else
Call TrimIt1
End If
Else
If Range("C17") = 3 Then
If Application.CountBlank(Range("C20:C23")) = 1 Or _
Application.CountBlank(Range("C26:C29")) = 1 Or _
Application.CountBlank(Range("C32:C35")) = 1 Then
MsgBox BlankRates
Else
Call TrimIt1
End If
Else
If Range("C17") = 4 Then
If Application.CountBlank(Range("C20:C23")) = 1 Or _
Application.CountBlank(Range("C26:C29")) = 1 Or _
Application.CountBlank(Range("C32:C35")) = 1 Or _
Application.CountBlank(Range("C38:C41")) = 1 Then
MsgBox BlankRates
Else
Call TrimIt1
End If
Else
Call TrimIt1
End If
End If
End If
End If
End Sub



--
Gordon Rainsford

London UK