Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default Updating records by status based on a formula.

Bob,

Here is the initial script that searches the records:

Private Sub UpdateListsButton_Click()
' Updates all Lists

MsgBox "You are about to update records. This may take a few minutes.",
vbOKOnly, "Notice"

Application.ScreenUpdating = False

' Verifies correct status
Sheet7.Visible = xlSheetVisible
Sheet2.Visible = xlSheetVisible
Sheet1.Visible = xlSheetVisible
Sheet1.Activate
Udts = 0
Rcds = Application.CountA(ActiveSheet _
.Range("X:X"))

Ind = "N"
Sts = "EXPIRED"

Set f = Columns(24).Find(What:=Ind)

If f Is Nothing Then
MsgBox "No records were found that needed updating.", vbOKOnly, "Update
Complete"
Exit Sub
End If

f.Offset(0, 0).Activate
Set PetSur = ActiveCell.Offset(0, -20)
Set PetNam = ActiveCell.Offset(0, -19)
Set RspSur = ActiveCell.Offset(0, -16)
Set RspNam = ActiveCell.Offset(0, -15)
Set IssDat = ActiveCell.Offset(0, -14)
Set ExpDat = ActiveCell.Offset(0, -13)
FF = PetSur & PetNam & RspSur & RspNam & IssDat & ExpDat

If ActiveCell.Offset(0, -21).Value = Sts Then
ActiveCell.EntireRow.Copy
Sheet2.Activate
LastPlc = Application.CountA(ActiveSheet _
.Range("D:D")) + 1 ' Finds last cell/row plus one
Cells(LastPlc, 1).PasteSpecial
Sheet7.Activate
LastPlc = Application.CountA(ActiveSheet _
.Range("A:A")) + 4 ' Finds last cell/row plus one
Cells(LastPlc, 1).Value = PetSur
Cells(LastPlc, 2).Value = PetNam
Cells(LastPlc, 3).Value = RspSur
Cells(LastPlc, 4).Value = RspNam
Cells(LastPlc, 5).Value = IssDat
Cells(LastPlc, 6).Value = ExpDat
Sheet1.Activate
Udts = Udts + 1
Rcds = Rcds - 1
End If

Set f = Columns(24).FindNext(After:=f)
f.Offset(0, 0).Activate

Do
Set PetSur = ActiveCell.Offset(0, -20)
Set PetNam = ActiveCell.Offset(0, -19)
Set RspSur = ActiveCell.Offset(0, -16)
Set RspNam = ActiveCell.Offset(0, -15)
Set IssDat = ActiveCell.Offset(0, -14)
Set ExpDat = ActiveCell.Offset(0, -13)
FND = PetSur & PetNam & RspSur & RspNam & IssDat & ExpDat
If FND = FF Then
Exit Do
End If
If ActiveCell.Offset(0, -21).Value = Sts Then
ActiveCell.EntireRow.Copy
Sheet2.Activate
LastPlc = Application.CountA(ActiveSheet _
.Range("D:D")) + 1 ' Finds last cell/row plus one
Cells(LastPlc, 1).PasteSpecial
Sheet7.Activate
LastPlc = Application.CountA(ActiveSheet _
.Range("A:A")) + 4 ' Finds last cell/row plus one
Cells(LastPlc, 1).Value = PetSur
Cells(LastPlc, 2).Value = PetNam
Cells(LastPlc, 3).Value = RspSur
Cells(LastPlc, 4).Value = RspNam
Cells(LastPlc, 5).Value = IssDat
Cells(LastPlc, 6).Value = ExpDat
Udts = Udts + 1
Sheet1.Activate
End If
Set f = Columns(24).FindNext(After:=f)
f.Offset(0, 0).Activate
Loop

Rcds = Application.CountA(ActiveSheet _
.Range("X:X"))

Ind = "N"
Sts = "TERMINATED"

Set f = Columns(24).Find(What:=Ind)
f.Offset(0, 0).Activate
Set PetSur = ActiveCell.Offset(0, -20)
Set PetNam = ActiveCell.Offset(0, -19)
Set RspSur = ActiveCell.Offset(0, -16)
Set RspNam = ActiveCell.Offset(0, -15)
Set IssDat = ActiveCell.Offset(0, -14)
Set ExpDat = ActiveCell.Offset(0, -13)
FF = PetSur & PetNam & RspSur & RspNam & IssDat & ExpDat

If ActiveCell.Offset(0, -21).Value = Sts Then
ActiveCell.EntireRow.Copy
Sheet2.Activate
LastPlc = Application.CountA(ActiveSheet _
.Range("D:D")) + 1 ' Finds last cell/row plus one
Cells(LastPlc, 1).PasteSpecial
Sheet7.Activate
LastPlc = Application.CountA(ActiveSheet _
.Range("A:A")) + 4 ' Finds last cell/row plus one
Cells(LastPlc, 1).Value = PetSur
Cells(LastPlc, 2).Value = PetNam
Cells(LastPlc, 3).Value = RspSur
Cells(LastPlc, 4).Value = RspNam
Cells(LastPlc, 5).Value = IssDat
Cells(LastPlc, 6).Value = ExpDat
Sheet1.Activate
Udts = Udts + 1
Rcds = Rcds - 1
End If

Set f = Columns(24).FindNext(After:=ActiveCell)
f.Offset(0, 0).Activate

Do
Set PetSur = ActiveCell.Offset(0, -20)
Set PetNam = ActiveCell.Offset(0, -19)
Set RspSur = ActiveCell.Offset(0, -16)
Set RspNam = ActiveCell.Offset(0, -15)
Set IssDat = ActiveCell.Offset(0, -14)
Set ExpDat = ActiveCell.Offset(0, -13)
FND = PetSur & PetNam & RspSur & RspNam & IssDat & ExpDat
If FND = FF Then
Exit Do
End If
If ActiveCell.Offset(0, -21).Value = Sts Then
ActiveCell.EntireRow.Copy
Sheet2.Activate
LastPlc = Application.CountA(ActiveSheet _
.Range("D:D")) + 1 ' Finds last cell/row plus one
Cells(LastPlc, 1).PasteSpecial
Sheet7.Activate
LastPlc = Application.CountA(ActiveSheet _
.Range("A:A")) + 4 ' Finds last cell/row plus one
Cells(LastPlc, 1).Value = PetSur
Cells(LastPlc, 2).Value = PetNam
Cells(LastPlc, 3).Value = RspSur
Cells(LastPlc, 4).Value = RspNam
Cells(LastPlc, 5).Value = IssDat
Cells(LastPlc, 6).Value = ExpDat
Udts = Udts + 1
Sheet1.Activate
End If
Set f = Columns(24).FindNext(After:=f)
f.Offset(0, 0).Activate
Loop

If Udts = 0 Then
MsgBox "All records are up-to-date. No records needed updated.", _
vbOKOnly, "No updates needed"
Exit Sub
End If

lp = 0

If Udts = 1 Then
Sheet7.Activate
ActiveSheet.PrintOut
Udts2 = Udts
Do Until Udts2 = 0
Udts2 = Udts - 1
lp = lp + 1
Cells(7, 1).Activate
ActiveCell.EntireRow.Delete
If lp = 1000 Then
Exit Do
End If
Loop
End If

Sheet7.Visible = xlSheetVeryHidden
Sheet2.Visible = xlSheetVeryHidden
Sheet1.Visible = xlSheetVeryHidden
Sheet4.Activate
Application.ScreenUpdating = True

MsgBox "All lists have been updated. " & Udts & " records have been
updated.", _
vbOKOnly, "Update Complete"

End Sub



This is the formula that returns the status of "VALID", "EXPIRED",
"TERMINATED", or "INVALID", which is the actual contents of the cells in
column "C":

=IF(D4="","INVALID",(IF(H4="","INVALID",(IF(M4="YE S","TERMINATED",(IF(K4="INDEF","VALID",(IF(ISTEXT( K4),"INVALID",(IF(K4=TODAY(),"VALID",(IF(K4="","I NVALID","EXPIRED")))))))))))))


Cell references here are as follows:

D4 - 1st Person Last name
H4 - 2nd Person Last name
M4 - Yes/No field if it has been terminated
K4 - Expiration date

Thanks for your help.
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Updating a Formula Based on Multiple sheets aks1983 Excel Worksheet Functions 6 May 5th 09 10:43 AM
reuest formula for auto update status & status date PERANISH Excel Worksheet Functions 5 June 2nd 08 04:26 PM
Updating old records law Excel Discussion (Misc queries) 0 December 2nd 07 03:01 PM
Excel status bar: How did I get 65533 records. sligg Excel Worksheet Functions 1 March 28th 07 02:43 AM
Excel status bar: How did I get 65533 records. Dave F Excel Worksheet Functions 0 March 28th 07 12:20 AM


All times are GMT +1. The time now is 05:13 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"