I've a list on the first worksheet cooresponding tot the worksheet name.
List is from 1 to ... and the name of worksheet is BT1, BT2, ....
Now Have I created a macro to delete a row from the list ande delete the specific worksheet, but after when the worksheet is deleted the rem2aining worksheets have to be renamed corresponding the numeric list.
Let say I delete Team 3, the teams are from 1 to 10. The code deletes the corresponding row and sheet, then it has first change the cell formula in the Cell (A?), so the list list is reset from 1 t0 9 and then changes the worksheet name.
I know that I need a loop for that, but don't know/understand how to write this type code.
I have the following Macro written. At the point of 'Loop to Rename worksheets I wanted to create a loop the rename the worksheets, but don't know/understand how to write the code.
Sub Team_Verwijderen()
Dim intMyVal As Integer, a As Integer
Dim lngLastRow As Long, i As Long
Dim strRowNoList As String, List2 As String, List_1 As String
Dim Zoekwaarde As Variant
Dim cell As Variant
Dim naam$, laatsteNaam$
Zoekwaarde = InputBox("Vul het Teamnummer in dat je wilt verwijderen.")
On Error GoTo Errorhandler
intMyVal = Zoekwaarde 'Value to search for, change as required.
lngLastRow = Cells(Rows.Count, "A").End(xlUp).Row 'Search Column A, change as required.
For Each cell In Range("A3:A" & lngLastRow) 'Starting cell is A2, change as required.
If cell.Value = intMyVal Then
If strRowNoList = "" Then
strRowNoList = strRowNoList & cell.Row
Else
strRowNoList = strRowNoList & ", " & cell.Row
End If
End If
Next cell
List2 = strRowNoList
List_1 = Range("A" & strRowNoList).Value
Sheets("BT" & List_1).Delete
Blad1.Range("A" & strRowNoList & ":K" & strRowNoList).Delete xlUp
'Loop to Rename worksheets
naam = "BT" & List_1
Range("A" & List2).Formula = "=if(B" & List2 & "="""","""",A" & List2 - 1 & "+1)"
Sheets("BT" & List_1 + 1).Name = naam
'-------------------------
Errorhandler:
Blad1.Select
Range("B3").Select
End Sub