[英]Excel Merging Cells into one column on bulk data
我很難處理布局錯誤的供應商發送的產品數據。 我希望每個產品的規范都放在不同的列中。 但是,他們將它們分為兩列,這給生活帶來了困難。
我有一個要使用的公式,但是,我需要將其向下拖動並跳過不屬於該產品的行。
例如:C2至C8和D2至D8包含產品10000ES的數據,下一個產品將需要C9至C18和D9至D18的數據。
我希望在我的HTML網站中使用此公式來使用CON CONCATENATE。 但是,如果我將其拖下,它將捕獲不需要的單元格。
=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
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.