-3
Sub Concat()

   Do While ActiveCell <> "" 

      'The rows are filtered to display only "London"
      'The changes required are for "London" only

      If ActiveCell.Offset(0,0) = "London" Then
        ActiveCell.Offset(0, 0).FormulaR1C1 = _
           ActiveCell.Offset(0, 0) & " " & ActiveCell.Offset(0, 1)

        ActiveCell.Offset(0, 1) = ""
      End If
      ActiveCell.Offset(1, 0).Select
   Loop

End Sub

我有接近 13500 行。这行不通。我看不到任何明显的变化。

4

2 回答 2

1
Sub Concat()

   Do While ActiveCell <> "" 

      With ActiveCell
         If .Value = "London" Then
             .Value = .Value & .Offset(0, 1).Value
             .Offset(0, 1).Value = ""
         End If
      End With

      ActiveCell.Offset(1, 0).Select

    Loop

End Sub
于 2013-02-15T06:34:33.273 回答
0

您可以使用for each语句编写一个循环,以遍历工作表的 UsedRange 中的所有行。对于每一行,检查该行第一列中的值是否为“London”,如果是,则使用 column1 和 column2 的组合覆盖该列的内容。

然后只需将 column3 中的值复制到 column2 并使用以下命令清除 column3 的值ClearContents

Sub Concat()

    'Loop through all the rows
    For Each Row In ActiveSheet.UsedRange.Rows

    'Look at the cell in the first column of the current row
    'If value is "London" concatinate column 1 and 2 and store in column1
    'Note, the check for "London" is an exact, case sensative check!

        If Row.Columns(1) = "London" Then
            Row.Columns(1) = Row.Columns(1) & " " & Row.Columns(2)
            Row.Columns(2) = Row.Columns(3)
            Row.Columns(3).ClearContents
        End If
    Next Row
End Sub
于 2013-02-15T08:27:43.667 回答