Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8318635
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T22:02:39+00:00 2026-06-08T22:02:39+00:00

Need some help with the following: I have several worksheets with the same structure

  • 0

Need some help with the following:

I have several worksheets with the same structure and within each worksheet I have two columns (let’s call them X & Y) that I need to copy with their cellvalues (letter-number combination) and also copy the values of Column A-F to an own sheet for X and Y.

On the “new” sheet I want to put X/Y to column A sort the values after A and attach a constant hyperlink to each cellvalue in A.
So X or Y goes to A and A-F to B-G.

Then I want to make column F or the new G clickable so that it will take me to the row in the according worksheet.
X and Y don’t always happen to be in column X or Y but I think this can be solved with a “name search”.

When I execute my code then for example worksheet3 will overwrite the values of worksheet1 and my hyperlink structure is wrong too. The sorting is left out since that is working.

Function CopyAndSort(ByRef mySheet As Worksheet)
'   If mySheet.Name <> "Sheet1" Then
'   Exit Function
'   End If

   mySheet.Activate
    Set sheetCS = Sheets("CopyAndSort Sheet")
    sheetCS.Range("A:A").Value = ""
   lastRowCS = Range("X:X").Cells.Find("*", , , , , xlPrevious).Row

     rowNumber = 1
    For rowCopy = 5 To lastRowFO
        sheetCopy = Range("BE" & rowCopy)
        If Trim(sheetCopy) <> "" Then
            sheetCopy = Replace(sheetCopy, """", "")
            If InStr(1, sheetCopy, ",", vbTextCompare) <> 0 Then
               sheetCopyArray = Split(sheetCopy, ",")
            Else
               sheetCopyArray = Array(sheetCopy)
      End If

            For Each copy In sheetCopyArray

                rowNumber = rowNumber + 1

                        copy_Value = copy
' test for url                         
'  sheetCS.Cells(rowNumber, 1).Formula = "=HYPERLINK(""ConstURL & copyValue"")"

                     sheetCS.Cells(rowNumber, 1) = copy_Value
                        copy_Value = Cells(rowCopy, 1)
                            sheetCS.Cells(rowNumber, 2) = copy_Value
                        copy_Value = Cells(rowCopy, 2)
                            sheetCS.Cells(rowNumber, 3) = copy_Value
                        copy_Value = Cells(rowCopy, 3)
                            sheetCS.Cells(rowNumber, 4) = copy_Value
                            copy_Value = Cells(rowCopy, 4)
                            sheetCS.Cells(rowNumber, 5) = copy_Value
                        copy_Value = Cells(rowCopy, 5)
                            sheetCS.Cells(rowNumber, 6) = copy_Value

            Next
        End If

    Next 

So how can I manage to not overwrite the values and attach the correct hyperlink syntax, plus making colum G clickable?
And can I use one function for X and Y?
Some code examples would help me alot.
Thank you.

UPDATE:

i forgot to mention that X & Y will always be next to each other.

Example:

Sheet1:

|ColA|ColB|ColC|ColD|ColF|....|ColX|ColY|

Sheet2: here “ColX” is in ColQ and ColY in ColR

|ColA|ColB|ColC|ColD|ColF|....|ColXinColQ|ColYinColR|

CopySheet_of_X: now copy ColX plus ColA-ColF of Sheet1 and do the same for Sheet2 where X is in ColQ

Output for both sheets:
|ColX|ColA|ColB|ColC|ColD|ColF|

CopySheet_of_Y: now copy ColY plus ColA-ColF of Sheet1 and do the same for Sheet2 where Y is in ColR

Output for both sheets:
|ColY|ColA|ColB|ColC|ColD|ColF|

Hyperlink:
so now the values of ColX and ColY should be concatenated with a preceding hyperlink:
If a cell in ColX has the value of “someValue1” then it should be turned into myurl://sometext=someValue1

and I don’t know the right way to jump back to the row when clicking on ColF.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-08T22:02:41+00:00Added an answer on June 8, 2026 at 10:02 pm

    Try this. Paste this in a module and run Sub Sample.

    Option Explicit
    
    Const hLink As String = "d3://d3explorer/idlist="
    
    Sub Sample()
        Dim sheetsToProcess
    
        Set sheetsToProcess = Sheets(Array("Sheet1", "Sheet2"))
    
        CopyData sheetsToProcess, "CopySheet_of_X", "FirstLinkValue"
    
        '~~> Similarly for Y
        'CopyData sheetsToProcess, "CopySheet_of_Y", "SecondLinkValue"
    End Sub
    
    '~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~'
    '                      USAGE                         '
    ' wsI      : Worksheet Collection                    '
    ' wsONm    : name of the new sheet for output        '
    ' XY       : Name of the X or Y Header               '
    '~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~'
    Sub CopyData(wsI, wsONm As String, XY As String)
        Dim ws As Worksheet, sSheet As Worksheet
        Dim aCell As Range
        Dim lRow As Long, LastRow As Long, lCol As Long, i As Long, j As Long
        Dim MyAr() As String
    
        '~~> Delete the Output sheet if it is already there
        On Error Resume Next
        Application.DisplayAlerts = False
        Sheets(wsONm).Delete
        Application.DisplayAlerts = True
        On Error GoTo 0
    
        '~~> Recreate the output sheet
        Set ws = Sheets.Add: ws.Name = wsONm
    
        '~~> Create Headers in Output Sheet
        ws.Range("A1") = XY
        wsI(1).Range("A3:F3").Copy ws.Range("B1")
    
        '~~> Loop throught the sheets array
        For Each sSheet In wsI
            LastRow = ws.Range("A" & ws.Rows.Count).End(xlUp).Row + 1
            With Sheets(sSheet.Name)
                '~~> Find the column which has X/Y header
                Set aCell = .Rows(3).Find(What:=XY, LookIn:=xlValues, _
                LookAt:=xlWhole, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
                MatchCase:=False, SearchFormat:=False)
    
                If aCell Is Nothing Then
                    '~~> If not found, inform and exit
                    MsgBox XY & " was not found in " & .Name, vbCritical, "Exiting Application"
                    Exit Sub
                Else
                    '~~> if found then get the column number
                    lCol = aCell.Column
    
                    '~~> Identify the last row of the sheet
                    lRow = .Range("A" & .Rows.Count).End(xlUp).Row
    
                    '~~> Loop through the X Column and split values
                    For i = 4 To lRow
                        If InStr(1, .Cells(i, lCol), ",") Then '<~~ If values like A1,A2,A3
                            MyAr = Split(.Cells(i, lCol), ",")
    
                            For j = 0 To UBound(MyAr)
                                '~~> Add hyperlink in Col 1
                                With ws
                                    .Cells(LastRow, 1).Value = MyAr(j)
                                    .Hyperlinks.Add Anchor:=.Cells(LastRow, 1), Address:= _
                                    hLink & .Cells(LastRow, 1).Value, TextToDisplay:=.Cells(LastRow, 1).Value
                                End With
    
                                .Range("A" & i & ":F" & i).Copy ws.Range("B" & LastRow)
    
                                '~~> Add hyperlink in Col 2
                                With ws
                                    .Hyperlinks.Add Anchor:=.Cells(LastRow, 7), Address:="", SubAddress:= _
                                    sSheet.Name & "!" & "A" & i, TextToDisplay:=.Cells(LastRow, 7).Value
                                End With
    
                                LastRow = LastRow + 1
                            Next j
                        Else  '<~~ If values like A1
                            '~~> Add hyperlink in Col 1
                            With ws
                                .Cells(LastRow, 1).Value = Sheets(sSheet.Name).Cells(i, lCol)
                                .Hyperlinks.Add Anchor:=.Cells(LastRow, 1), Address:= _
                                hLink & .Cells(LastRow, 1).Value, TextToDisplay:=.Cells(LastRow, 1).Value
                            End With
    
                            .Range("A" & i & ":F" & i).Copy ws.Range("B" & LastRow)
    
                            '~~> Add hyperlink in Col 2
                            With ws
                                .Hyperlinks.Add Anchor:=.Cells(LastRow, 7), Address:="", SubAddress:= _
                                sSheet.Name & "!" & "A" & i, TextToDisplay:=.Cells(LastRow, 7).Value
                            End With
    
                            LastRow = LastRow + 1
                        End If
                    Next i
                End If
            End With
        Next
    
        '~~> Sort the data
        ws.Columns("A:G").Sort Key1:=ws.Range("A2"), Order1:=xlAscending, Header:=xlGuess, _
        OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom, DataOption1:=xlSortNormal
    End Sub
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need some help writing a regex. I have the following strings, xxx.yyy.wwwwwaaa_IN_123 xxx.rrrttttt_IN_12355
I need some help with something... say I have the following form... <form name=
I need some help with a JDO query. I have the following Entities: recipe:
I need some help optimizing the following method. The queries have become too costly
I need some help with query from multiple tables. My database: I have following
i need some help to write two URL rewrite rules in IIS7, i have
Hi I need some help with the following scenario in php. I have a
I have the following strange situation here I need some help with: I am
I need some help extracting the following bits of information using regular expressions. Here
I need some help solving some compile errors. I was following a tutorial (at

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.