简体   繁体   中英

Excel Merging Cells into one column on bulk data

I am having great difficulty with product data sent from a supplier that is in a bad layout. I wanted the specification to be in separate columns for each product. However, they have listed them in 2 columns making life difficult.

I have a formula that I want to use, however, I need to drag this down and skip rows that don't belong to that product.

For example: C2 to C8 and D2 to D8 consist of data for product 10000ES, the next product would need data from C9 to C18 and D9 to D18.

The formula I wish to use TO CONCATENATE as I wish to use this in my HTML website. But if I drag this down it would capture cells I do not want.

=CONCATENATE("<tr>",F2,"<tr>",F3,"<tr>",F4,"<tr>",F5,"<tr>",F6,"<tr>",F7,"<tr>",F8,"<tr>",F9,"<tr>",F10,"<tr>")

Excel工作表的图像

I think I can determine what you're after, based on the output I can make out in cell G2.. Try this:

Sub TryThis()

Dim rng As Range, writeto As Range
Dim outpt As String

Set rng = ActiveSheet.Range("B1:D38") ' set this to cover the range down to the bottom

Set writeto = ActiveSheet.Range("G:G") ' this is the column to output to

For Each rw In rng.Rows
    If rw.Cells(1, 2) <> "" Then
        If rw.Cells(1, 1) = 1 Then
            writeto.Cells(writeto.Rows.Count, 1).End(xlUp).Offset(1, 0) = outpt
            outpt = ""
        End If
        outpt = outpt & "<tr>"
        outpt = outpt & "<th>" & rw.Cells(1, 2) & "</th>"
        outpt = outpt & "<td>" & rw.Cells(1, 3) & "</td>"
    End If
Next
outpt = outpt & "<tr>"
writeto.Cells(writeto.Rows.Count, 1).End(xlUp).Offset(1, 0) = outpt
End Sub

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM