concatenating excel cells with a loop

Hey folks,

I have a workbook with 2 sheets, sheet1 is the "input" and sheet2 is the "output". basically, I'm trying to find a way to derive the sheet2 output from the sheet1 input using a macro.

Essentially, the input sheet is the raw data, the output sheet is creating the skus for something else. The skus created are a combination of cells A+B+ the title and the value for c-n (this'll make more sense by looking at the sample output)

Any help greatly appreciated.

Copy-of-sample-input-1.xls
merv109Asked:
Who is Participating?
 
SiddharthRoutCommented:
Please find a sample attached.

Simply run the macro Sample which is there in the module.

Hope this helps.

Sid

Code Used

Sub Sample()
    Dim ws1 As Worksheet, ws2 As Worksheet
    Dim ws1LastRow As Long, ws2LastRow As Long
    Dim i As Long, j As Long
    
    Set ws1 = Sheets("Input")
    Set ws2 = Sheets("output")
    
    ws1LastRow = ws1.Range("A" & Rows.Count).End(xlUp).Row
    ws2LastRow = ws2.Range("A" & Rows.Count).End(xlUp).Row + 1
    
    For i = 2 To ws1LastRow
        For j = 3 To 14
            ws2.Range("A" & ws2LastRow).Value = ws1.Range("A" & i).Value & _
                                                "-" & _
                                                ws1.Range("B" & i).Value & _
                                                ws1.Cells(1, j).Value
            ws2.Range("B" & ws2LastRow).Value = ws1.Cells(1, j).Offset(1).Value
            ws2LastRow = ws2LastRow + 1
        Next j
    Next i
End Sub

Open in new window

sample-input-1.xls
0
 
SiddharthRoutCommented:
What is the logic behind deciding on "Y" or "N"?

Sid
0
 
SiddharthRoutCommented:
Ok Ok. Got it.

Few moments

Sid
0
 
merv109Author Commented:
Perfect, exactly what I was after. Thanks!
0
 
merv109Author Commented:
Thanks again!
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.