Hi All.. Im new to Macros..so getting an error..the macro has to basically check whether there exists a worksheet with a certain name (the name is in BF column) if it exists den do nothing. if does not exist den create a copy of an existing worksheet and rename it with name in BF column.Repeat this for all the rows in BF column.
what changes should be done in the below macro to work properly. pls help
Sub CopySheetAndRename()
For i = 1 To Worksheets.count
For r = 1 To Rows.count
If Worksheets(i).Name = Range("BF" & r + 1) Then
exists = True
End If
Next i
If Not exists Then
Dim ws As Worksheet
Set ws = ActiveSheet
Worksheets("CopySheet").Copy After:=Worksheets("Misc")
If ws.Range("BF" & r + 1).Value <> "" Then
On Error Resume Next
ActiveSheet.Name = ws.Range("BF" & r + 1).Value
End If
Next r
ws.Activate
End If
End Sub
Thanks in Advance
what changes should be done in the below macro to work properly. pls help
Sub CopySheetAndRename()
For i = 1 To Worksheets.count
For r = 1 To Rows.count
If Worksheets(i).Name = Range("BF" & r + 1) Then
exists = True
End If
Next i
If Not exists Then
Dim ws As Worksheet
Set ws = ActiveSheet
Worksheets("CopySheet").Copy After:=Worksheets("Misc")
If ws.Range("BF" & r + 1).Value <> "" Then
On Error Resume Next
ActiveSheet.Name = ws.Range("BF" & r + 1).Value
End If
Next r
ws.Activate
End If
End Sub
Thanks in Advance