Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

concatenating excel cells with a loop

Posted on 2011-04-24
5
Medium Priority
?
250 Views
Last Modified: 2012-05-11
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
0
Comment
Question by:merv109
  • 3
  • 2
5 Comments
 
LVL 30

Expert Comment

by:SiddharthRout
ID: 35455384
What is the logic behind deciding on "Y" or "N"?

Sid
0
 
LVL 30

Expert Comment

by:SiddharthRout
ID: 35455387
Ok Ok. Got it.

Few moments

Sid
0
 
LVL 30

Accepted Solution

by:
SiddharthRout earned 2000 total points
ID: 35455419
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
 

Author Comment

by:merv109
ID: 35456854
Perfect, exactly what I was after. Thanks!
0
 

Author Closing Comment

by:merv109
ID: 35456855
Thanks again!
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Freeze panes is an option within all variants of Excel to enable parts of a sheet to remain stationary when the cursor is in another part of the sheet. This is a very useful feature which is overlooked or under used.
After seeing numerous questions for Dynamic Data Validation I notice that most have used Visual Basic to solve the problem. This suggestion is purely formula based and can be used in multiple rows.
This Micro Tutorial will demonstrate in Google Sheets how to use the HYPERLINK function to create live links inside your spreadsheet.
This Micro Tutorial will demonstrate in Microsoft Excel how to add style and sexy appeal to horizontal bar charts.

810 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question