Modify macro so that ithe liste contents shall reformated to its left side

Chaturvedi, Santosh 450 Reputation points
2026-10-05T11:01:44.9033333+00:00

Can u modify the below macro so that the final liste in F20 shall be placed at right side of the table..


Sub CopyAndRenameSheets()

Dim wsDash As Worksheet

Dim wsTemplate As Worksheet

Dim wsNew As Worksheet

Dim wsInsertAfter As Worksheet

Dim lastRow As Long

Dim i As Long

Dim newName As String

Dim outRow As Long

Set wsDash = ThisWorkbook.Worksheets("Dash Board")

Set wsTemplate = ThisWorkbook.Worksheets("Master_Template")

Set wsInsertAfter = wsTemplate

lastRow = wsDash.Cells(wsDash.Rows.Count, "C").End(xlUp).Row

outRow = 20

For i = 20 To lastRow

    newName = Trim(wsDash.Cells(i, "C").Value)

    If newName <> "" Then

        wsTemplate.Copy After:=wsInsertAfter

        Set wsNew = ActiveSheet

        wsNew.Name = newName

        wsDash.Cells(outRow, "F").Value = newName

        wsDash.Hyperlinks.Add _

            Anchor:=wsDash.Cells(outRow, "F"), _

            Address:="", _

            SubAddress:="'" & newName & "'!A1", _

            TextToDisplay:=newName

        Set wsInsertAfter = wsNew

        outRow = outRow + 1

    End If

Next i

End Sub

Microsoft 365 and Office | Excel | For business | Windows
0 comments No comments

Answer accepted by question author
Aetherin 2,505 Reputation points Independent Advisor
2026-10-05T11:18:18.6766667+00:00

Hi @Chaturvedi, Santosh,

If you want the list in column F, starting from F20, to be right-aligned, use the following modified macro:

Sub CopyAndRenameSheets()

    Dim wsDash As Worksheet
    Dim wsTemplate As Worksheet
    Dim wsNew As Worksheet
    Dim wsInsertAfter As Worksheet
    Dim lastRow As Long
    Dim i As Long
    Dim newName As String
    Dim outRow As Long
    Set wsDash = ThisWorkbook.Worksheets("Dash Board")
    Set wsTemplate = ThisWorkbook.Worksheets("Master_Template")
    Set wsInsertAfter = wsTemplate
    lastRow = wsDash.Cells(wsDash.Rows.Count, "C").End(xlUp).Row
    outRow = 20
    For i = 20 To lastRow
        newName = Trim(wsDash.Cells(i, "C").Value)
        If newName <> "" Then
            wsTemplate.Copy After:=wsInsertAfter
            Set wsNew = ActiveSheet
            wsNew.Name = newName
            wsDash.Hyperlinks.Add _
                Anchor:=wsDash.Cells(outRow, "F"), _
                Address:="", _
                SubAddress:="'" & newName & "'!A1", _
                TextToDisplay:=newName
            ' Right-align the list entry in column F
            wsDash.Cells(outRow, "F").HorizontalAlignment = xlRight
            Set wsInsertAfter = wsNew
            outRow = outRow + 1
        End If
    Next i

End Sub

The added line is:

wsDash.Cells(outRow, "F").HorizontalAlignment = xlRight

This will right-align the content of each cell containing a hyperlink in column F.

I hope this helps. If there's any issue or if I've misunderstood your question, please feel free to reply and let me know.


If the answer is helpful, please kindly click "Yes" button below. If you have extra questions about this answer, please click "Comment".    

Note: Please follow the steps in the forum documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

Was this answer helpful?

1 person found this answer helpful.
0 comments No comments

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.