Macro to List Sheets from

howard

Well-known Member
Joined
Jun 26, 2006
Messages
6,563
Office Version
  1. 2021
Platform
  1. Windows
I have the folowing cosde to list sheet RDM TE-ATBA from to the last sheet in Col L1 onwards on sheet macro as well as the values on these sheets that are in C29 in M1 onwards

The macro is not listing all the sheeets from RDM TE-ATBA to the last sheet

It would be appreciated if someone could amend my code


Code:
 Sub ListChequeAdviseSheets()
   
    Dim ws As Worksheet
    Dim lastSheet As Long
    Dim i As Long
    Dim rowCounter As Long
   
    rowCounter = 1
   
    'Get the last sheet in the workbook
    lastSheet = Worksheets.Count
   
    'Loop through the worksheets
    For i = Sheets("RDM TE-ATBA").Index To Worksheets.Count
        Set ws = Worksheets(i)
       
        'Check if the worksheet name is between "RDM TE-ATBA" and the last sheet
        If ws.Name >= "RDM TE -ATBA" And i <= lastSheet Then
            'Write the worksheet name to column L
            Worksheets("Macro").Cells(rowCounter, 12).Value = ws.Name
           
            'Write the value of cell C29 on the worksheet to column M
            Worksheets("Macro").Cells(rowCounter, 13).Value = ws.Range("C29").Value
           
            rowCounter = rowCounter + 1 'Increment the row counter
        End If
    Next i
End Sub
 

Excel Facts

Do you hate GETPIVOTDATA?
Prevent GETPIVOTDATA. Select inside a PivotTable. In the Analyze tab of the ribbon, open the dropown next to Options and turn it off
Does this do what you want...

VBA Code:
Sub ListChequeAdviseSheets()
   
    Dim i As Long
    Dim rowCounter As Long
    
    rowCounter = 1
   
    'Loop through the worksheets
    For i = Sheets("RDM TE-ATBA").Index + 1 To Worksheets.Count
        'Write the worksheet name to column L
        With Worksheets(i)
            Worksheets("Macro").Cells(rowCounter, 12).Value = .Name
        'Write the value of cell C29 on the worksheet to column M
            Worksheets("Macro").Cells(rowCounter, 13).Value = .Range("C29").Value
        End With
        rowCounter = rowCounter + 1
    Next i
    
End Sub
 
Upvote 0
Solution
Many Thnks for the help.

I amended code below and it then worked perfectly


Code:
  For i = Sheets("RDM TE-ATBA").Index + 1 To Worksheets.Count

to

 For i = Sheets("RDM TE-ATBA").Index To Worksheets.Count
 
Upvote 0
You're welcome, I was happy to help. Thanks for the feedback.
 
Upvote 0

Forum statistics

Threads
1,215,133
Messages
6,123,235
Members
449,092
Latest member
SCleaveland

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top