Anthony904
IS-IT--Management
I have a spreadsheet that keeps an Inventory of some backup tapes.
The spreadsheet looks like so:
Worksheet: "Tape Data"
Slot Tape Date Used
1 ABC 4/9/07 Full
2 CBS 4/8/07 Full
3 NBC -------- 0%
Slot = Where the tape currently resides in the jukebox
Tape = Name of tape
Used = Amount stored on the tapes
Date = Represents the date the tapes where taken out of the jukebox + 90 days (data retention period)
The spreadsheet finds fields that are marked "Full" and moves it over to worksheet "Inventory" and clear the contents from "Tape Data".
The code below works fine if column "Used" has a "Full" tape, but if there is not it copies all tapes over "Full" or not. It also clears the "Tape Data" worksheet.
Thanks.
The spreadsheet looks like so:
Worksheet: "Tape Data"
Slot Tape Date Used
1 ABC 4/9/07 Full
2 CBS 4/8/07 Full
3 NBC -------- 0%
Slot = Where the tape currently resides in the jukebox
Tape = Name of tape
Used = Amount stored on the tapes
Date = Represents the date the tapes where taken out of the jukebox + 90 days (data retention period)
The spreadsheet finds fields that are marked "Full" and moves it over to worksheet "Inventory" and clear the contents from "Tape Data".
The code below works fine if column "Used" has a "Full" tape, but if there is not it copies all tapes over "Full" or not. It also clears the "Tape Data" worksheet.
Code:
Private Sub CommandButton1_Click()
Dim rg As Range
Dim ws As Worksheet, wsUpload As Worksheet
On Error Resume Next
Application.ScreenUpdating = False
Set wsUpload = Worksheets("Inventory")
For Each ws In ActiveWorkbook.Worksheets
If ws.Name <> "Inventory" Then
Set rg = Intersect(ws.UsedRange, ws.Range("B:D"))
rg.AutoFilter Field:=3, Criteria1:="Full" 'The 3 refers to the third column in the filtered range
rg.Offset(1, 0).Resize(rg.Rows.Count - 1).Copy wsUpload.Cells(65536, 1).End(xlUp).Offset(1, 0)
rg.Offset(1, 0).Resize(rg.Rows.Count - 1).ClearContents
ws.Cells(1, 1).AutoFilter
rs.Delete
End If
Next
Application.ScreenUpdating = True
MsgBox "Tapes Moved to ""Inventory"""
End Sub
Thanks.