【问题标题】:How to merge cells table that have same values如何合并具有相同值的单元格表
【发布时间】:2018-08-06 00:22:11
【问题描述】:

我正在尝试创建一个表。如果单元格的属性值与“可用”或“不”等另一个相同,我想合并表格单元格。我想不出如何用 jQuery、JavaScript 或任何其他语言来做到这一点。


我有以下代码:

<html>
    <table>
        <thead>
            <tr>
                <th>NO </th>
                <th> name </th>
                <th> 2018-1-1 </th>
                <th> 2018-1-2 </th>
                <th> 2018-1-3 </th>
                <th> 2018-1-4 </th>
                <th> 2018-1-5 </th>
            </tr>
        </thead>
        <tbody>
            <tr>
                <td> 1 </td>
                <td> Mark Tony </td>
                <td>Available  </td>
                <td>Available  </td>
                <td>Available  </td>
                <td>Not  </td>
                <td>Not  </td>
            </tr>
            <tr>
                <td> 2 </td>
                <td> Susan Tom </td>
                <td>Not  </td>
                <td>Available  </td>
                <td>Available  </td>
                <td>Not  </td>
                <td>Not  </td>
            </tr>
        </tbody>
    </table>
</html>

【问题讨论】:

标签: javascript jquery html css


【解决方案1】:

Sub MergeSameCell()

Dim Rng As Range, xCell As Range
Dim xRows As Integer, xRows1 As Integer
Dim LastRowTE As Long

LastRowTE = Worksheets("Test_Execution").Cells(Worksheets("Test_Execution").Rows.Count, "A").End(xlUp).Row
Set WorkRng = Range("A2:A" & LastRowTE)
Set WorkRng1 = Range("B2:B" & LastRowTE)

Application.ScreenUpdating = False
Application.DisplayAlerts = False

xRows = WorkRng.Rows.Count
xRows1 = WorkRng1.Rows.Count

For Each Rng In WorkRng.Columns
    For i = 1 To xRows - 1
        For j = i + 1 To xRows
            If Rng.Cells(i, 1).Value <> Rng.Cells(j, 1).Value Then
                Exit For
            End If
        Next
        WorkRng.Parent.Range(Rng.Cells(i, 1), Rng.Cells(j - 1, 1)).Merge
        i = j - 1
    Next
Next

For Each Rng In WorkRng1.Columns
    For i = 1 To xRows1 - 1
        For j = i + 1 To xRows1
            If Rng.Cells(i, 1).Value <> Rng.Cells(j, 1).Value Then
                Exit For
            End If
        Next
        WorkRng1.Parent.Range(Rng.Cells(i, 1), Rng.Cells(j - 1, 1)).Merge
        i = j - 1
    Next
Next

Application.DisplayAlerts = True
Application.ScreenUpdating = True

Range("A1:O" & LastRowTE).WrapText = True

结束子

【讨论】:

    【解决方案2】:

    私有子命令按钮1_Click()

    Worksheets("Test_Execution").Rows("1:" & Worksheets("Test_Execution").Rows.Count).Delete
    Call Worksheets("Requirement_JIRAs").SliceNDice
    Call Worksheets("Test_Execution").vlookupJira
    Call Worksheets("Test_Execution").DeleteRowBasedOnCriteria
    Call Worksheets("Test_Execution").MergeSameCell
    Call Worksheets("Test_Execution").FinalTableFormat
    Call Worksheets("Test_JIRAs").StatusReport_TestingTable
    

    结束子

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2019-10-28
      • 1970-01-01
      • 1970-01-01
      • 2020-08-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多