0% found this document useful (0 votes)
8 views2 pages

BMR BPR Code

The document contains two VBA subroutines for Excel. The first subroutine, RenameSheets, renames each worksheet in the workbook sequentially with numbers starting from 1. The second subroutine, AddSheetNumber, finds the text 'of 26' in row 4 of each worksheet and prepends the sheet number to it, while also cleaning up any existing text before 'of 26'.

Uploaded by

xohel46436
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views2 pages

BMR BPR Code

The document contains two VBA subroutines for Excel. The first subroutine, RenameSheets, renames each worksheet in the workbook sequentially with numbers starting from 1. The second subroutine, AddSheetNumber, finds the text 'of 26' in row 4 of each worksheet and prepends the sheet number to it, while also cleaning up any existing text before 'of 26'.

Uploaded by

xohel46436
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

Sub RenameSheets()

Dim ws As Worksheet

Dim i As Integer

i=1

For Each ws In ThisWorkbook.Worksheets

ws.Name = CStr(i)

i=i+1

Next ws

End Sub
Sub AddSheetNumber()

Dim ws As Worksheet

Dim i As Integer

Dim newName As String

i=1

For Each ws In ThisWorkbook.Worksheets

' Find "of 26" in row 4 and add sheet number before it

Dim rng As Range

Set rng = ws.Rows(4).Find(What:="of 26", LookIn:=xlValues, LookAt:=xlPart, _

SearchOrder:=xlByColumns, SearchDirection:=xlNext, MatchCase:=False)

If Not rng Is Nothing Then

' Delete existing text before "of 26"

Dim pos As Integer

pos = InStr(1, rng.Value, "of 26", vbTextCompare)

If pos > 1 Then

rng.Value = Mid(rng.Value, pos - 1)

End If

' Add sheet number before "of 26"

rng.Value = i & " " & rng.Value

End If

i=i+1

Next ws

End Sub

You might also like