View Single Post
  #1   Report Post  
Posted to microsoft.public.excel.programming
Brad Brad is offline
external usenet poster
 
Posts: 846
Default Improvements to code

The below works - but if someone adds a column before "B' or a row before 3 -
this will cause problems. I know that offset could be used or perhaps using
r1c1 formating, but was wondering what some good alternative solutions would
be. I have other code that access column "F" and "AG" and would like the
solutions to handle them all.

Thanks in advance for your help....

Sub CheckdSingleDates()
Dim i As Long
Dim cntr1 As Long

Dim IMonth As Long
Dim IDay As Long

cntr1 = 0

IMonth = Month(shtInput.Range("Issdate"))
IDay = Day(shtInput.Range("issdate"))

For i = 1 To 5
Select Case shtSingleDeposits.Range("B" & 3 + i).Value
Case Is = 0
Case Is < shtInpInfo.Range("InpSingleFirst").Value
shtSingleDeposits.Range("B" & 3 + i).ClearContents
cntr1 = cntr1 + 1
Case Is shtInpInfo.Range("InpSingleFinal").Value
shtSingleDeposits.Range("B" & 3 + i).ClearContents
cntr1 = cntr1 + 1
Case Else
If Month(shtSingleDeposits.Range("B" & 3 + i).Value) <
IMonth Or Day(shtSingleDeposits.Range("B" & 3 + i).Value) < IDay Then
shtSingleDeposits.Range("B" & 3 + i).ClearContents
cntr1 = cntr1 + 1
End If
End Select
Next
If cntr1 0 Then
MsgBox ("Single Premium Date(s) have been deleted")
Module1.GotoSingle
End If
End Sub