+ Reply to Thread
Results 1 to 3 of 3

Reference A2 cell in individual sheets Vba Script

Hybrid View

  1. #1
    Valued Forum Contributor tek9step's Avatar
    Join Date
    05-27-2009
    Location
    London, England
    MS-Off Ver
    MS 365
    Posts
    395

    Post Reference A2 cell in individual sheets Vba Script

    I have below Vba Script where all the name of individual sheet get transfered in A column of new sheet called " Sheet Names" which is fine but what I would like to add to the script is all the A2 reference appearing in those indivual sheets also appearing in B column next to individual sheet names in sheet "Sheet Names".


    Sub ListSheetNames()
    
    Dim NumSheets
    NumSheets = Sheets.Count
    
    Application.DisplayAlerts = False
    Dim i
    For i = 1 To NumSheets
    Sheets(i).Select
    If ActiveSheet.Name = "SheetNames" Then
    Sheets("SheetNames").Select
    ActiveWindow.SelectedSheets.Delete
    Application.DisplayAlerts = True
    Exit Sub
    End If
    Next i
    
    Sheets.Add
    ActiveSheet.Name = "SheetNames"
    Sheets("SheetNames").Move after:=Sheets(NumSheets + 1)
    
    For i = 1 To NumSheets
    Range("A" & i) = Sheets(i).Name
    Next i
    
    End Sub



    Thank you
    Last edited by tek9step; 06-11-2009 at 07:40 AM.

  2. #2
    Forum Guru DonkeyOte's Avatar
    Join Date
    10-22-2008
    Location
    Northumberland, UK
    MS-Off Ver
    O365
    Posts
    21,531

    Re: Reference A2 cell in individual sheets Vba Script

    Something along the lines of the below perhaps ?

    Public Sub ListSheetNames()
    Dim i As Long, ws As Worksheet
    On Error Resume Next
    Application.DisplayAlerts = False
    Sheets("SheetNames").Delete
    Application.DisplayAlerts = True
    On Error GoTo 0
    Sheets.Add After:=Sheets(ThisWorkbook.Sheets.Count)
    ActiveSheet.Name = "SheetNames"
    For Each ws In ActiveWorkbook.Worksheets
        If ws.Name <> ActiveSheet.Name Then
            i = i + 1
            Cells(i, 1) = ws.Name
            Cells(i, 2) = ws.Cells(2, "A")
        End If
    Next ws
    End Sub

  3. #3
    Valued Forum Contributor tek9step's Avatar
    Join Date
    05-27-2009
    Location
    London, England
    MS-Off Ver
    MS 365
    Posts
    395

    Thumbs up Re: Reference A2 cell in individual sheets Vba Script

    Cheers it works perfect.. !!

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1