Excel 在批量数据上将单元格合并为一列
Excel Merging Cells into one column on bulk data
我很难处理布局不良的供应商发送的产品数据。我希望每个产品的规格都在单独的列中。但是,他们将它们列在 2 列中,使生活变得困难。
我有一个要使用的公式,但是,我需要将其向下拖动并跳过不属于该产品的行。
例如:C2到C8和D2到D8包含产品10000ES的数据,下一个产品需要C9到C18和D9到D18的数据。
我希望使用 TO CONCATENATE 的公式,因为我希望在我的 HTML 网站中使用它。但是,如果我将其向下拖动,它会捕获我不想要的单元格。
=CONCATENATE("<tr>",F2,"<tr>",F3,"<tr>",F4,"<tr>",F5,"<tr>",F6,"<tr>",F7,"<tr>",F8,"<tr>",F9,"<tr>",F10,"<tr>")
我想我可以根据我在单元格 G2 中得到的输出来确定你想要什么。试试这个:
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
我很难处理布局不良的供应商发送的产品数据。我希望每个产品的规格都在单独的列中。但是,他们将它们列在 2 列中,使生活变得困难。
我有一个要使用的公式,但是,我需要将其向下拖动并跳过不属于该产品的行。
例如:C2到C8和D2到D8包含产品10000ES的数据,下一个产品需要C9到C18和D9到D18的数据。
我希望使用 TO CONCATENATE 的公式,因为我希望在我的 HTML 网站中使用它。但是,如果我将其向下拖动,它会捕获我不想要的单元格。
=CONCATENATE("<tr>",F2,"<tr>",F3,"<tr>",F4,"<tr>",F5,"<tr>",F6,"<tr>",F7,"<tr>",F8,"<tr>",F9,"<tr>",F10,"<tr>")
我想我可以根据我在单元格 G2 中得到的输出来确定你想要什么。试试这个:
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