ilikered100
New Member
- Joined
- May 29, 2013
- Messages
- 46
Ok... The code works fine on one sheet, but I can't get it to move to the next worksheet and continue carrying out the code.
What the code does is start on a worksheet after a known worksheet name (EvaluationData). On all sheets after EvaluationData, the code loops down through cells starting on AF10 and deletes data that is NOT LIKE the sheet name.
This works fine on the first sheet after DataEvaluation, but I can't get it to move to the next sheet. Also when I can get it to go to the next worksheet, will the variable change to that new sheet name?... which I need it to do. I need the variable (strActiveSheetName) to change to the active worksheet name and then use that sheet name... etc.
I hope this makes sense.
Any help is appreciated.
Carolyn
-----------------
Sub Details_5()
Dim intFirstws As Integer
Dim strActiveSheetName As String
Dim i As Integer
intFirstws = Worksheets("EvaluationData").Index + 1
strActiveSheetName = ActiveSheet.Name
Worksheets(intFirstws).Select
Range("AF10").Select
'Range of sheets from the sheet after DataEvaluation to the end of all the sheets in the workbook
For i = intFirstws To Sheets.Count
Do Until ActiveCell.Value = ""
'If data is LIKE the sheet name then do nothing and move down one cell
If ActiveCell.Value Like strActiveSheetName & "*" Then
ActiveCell.Offset(1, 0).Select
'If data is NOT LIKE sheet name then delete that cell and the two cells to the left and shift other cells up
Else: Range(ActiveCell.Offset(0, 0), ActiveCell.Offset(0, -2)).Select
Selection.delete Shift:=xlUp
'Move back the the last cell active cell to continue evaluation of cells for LIKE or NOT LIKE sheet name
ActiveCell.Offset(0, 2).Select
End If
Loop
'Move onto next worksheet
Next i
End Sub
What the code does is start on a worksheet after a known worksheet name (EvaluationData). On all sheets after EvaluationData, the code loops down through cells starting on AF10 and deletes data that is NOT LIKE the sheet name.
This works fine on the first sheet after DataEvaluation, but I can't get it to move to the next sheet. Also when I can get it to go to the next worksheet, will the variable change to that new sheet name?... which I need it to do. I need the variable (strActiveSheetName) to change to the active worksheet name and then use that sheet name... etc.
I hope this makes sense.
Any help is appreciated.
Carolyn
-----------------
Sub Details_5()
Dim intFirstws As Integer
Dim strActiveSheetName As String
Dim i As Integer
intFirstws = Worksheets("EvaluationData").Index + 1
strActiveSheetName = ActiveSheet.Name
Worksheets(intFirstws).Select
Range("AF10").Select
'Range of sheets from the sheet after DataEvaluation to the end of all the sheets in the workbook
For i = intFirstws To Sheets.Count
Do Until ActiveCell.Value = ""
'If data is LIKE the sheet name then do nothing and move down one cell
If ActiveCell.Value Like strActiveSheetName & "*" Then
ActiveCell.Offset(1, 0).Select
'If data is NOT LIKE sheet name then delete that cell and the two cells to the left and shift other cells up
Else: Range(ActiveCell.Offset(0, 0), ActiveCell.Offset(0, -2)).Select
Selection.delete Shift:=xlUp
'Move back the the last cell active cell to continue evaluation of cells for LIKE or NOT LIKE sheet name
ActiveCell.Offset(0, 2).Select
End If
Loop
'Move onto next worksheet
Next i
End Sub