diygail123
New Member
- Joined
- Oct 24, 2018
- Messages
- 25
Hi
I have the below code which I was hoping would scroll through some worksheets in a workbook, and delete certain ranges of data. However, it is bugging at "Sheets(sName).Sheet. I am using the list of vendor codes on a separate worksheet as a collection. Can any of you guys see what I have wrong?
'DELETE OLD DATA FROM VENDOR TABS
Sub Delete()
'DECLARE VARIABLES
Dim colShts As New Collection
Dim sName As String
Dim ListOfVendorCodes As Range, c As Range
Dim i As Integer
Set ListOfVendorCodes = Worksheets("List of Vendor Codes").Range("b2:b57")
'SCROLL THROUGH VENDOR CODES
Sheets("List of Vendor Codes").Activate
Range("b2").Select
While ActiveCell.Value <> ""
colShts.Add ActiveCell.Value
ActiveCell.Offset(1, 0).Select 'next row
Wend
For i = 1 To colShts.Count
sName = colShts(i)
'DELETE THE OLD DATA
Sheets(sName).Select 'bugging here
Range("A7:k860").ClearContents
Range("L864:M864").ClearContents
Range("h868:I868").ClearContents
Next
Set colShts = Nothing
End Sub
I have the below code which I was hoping would scroll through some worksheets in a workbook, and delete certain ranges of data. However, it is bugging at "Sheets(sName).Sheet. I am using the list of vendor codes on a separate worksheet as a collection. Can any of you guys see what I have wrong?
'DELETE OLD DATA FROM VENDOR TABS
Sub Delete()
'DECLARE VARIABLES
Dim colShts As New Collection
Dim sName As String
Dim ListOfVendorCodes As Range, c As Range
Dim i As Integer
Set ListOfVendorCodes = Worksheets("List of Vendor Codes").Range("b2:b57")
'SCROLL THROUGH VENDOR CODES
Sheets("List of Vendor Codes").Activate
Range("b2").Select
While ActiveCell.Value <> ""
colShts.Add ActiveCell.Value
ActiveCell.Offset(1, 0).Select 'next row
Wend
For i = 1 To colShts.Count
sName = colShts(i)
'DELETE THE OLD DATA
Sheets(sName).Select 'bugging here
Range("A7:k860").ClearContents
Range("L864:M864").ClearContents
Range("h868:I868").ClearContents
Next
Set colShts = Nothing
End Sub