如果长度为<则复制单元格值。 10进入VBA之上的最后一个单元格值字符串

时间:2017-02-20 12:12:19

标签: excel vba excel-vba

我已经将文本文件导入excel,会发生一些文本突破到下一行,即

ColumnA
--------------
1313 Disneyland Dr, Anaheim, CA 92802
, USA  '<---Copy/Cut cell value into the last string above cell
1600 Amphitheatre Parkway Mountain View, CA 94043 United
States '<---Copy/Cut cell value into the last string above cell

期望的输出

ColumnA
--------------
1313 Disneyland Dr, Anaheim, CA 92802, USA
1600 Amphitheatre Parkway Mountain View, CA 94043 United States

我已经提出了这个代码,但我在最后一个单元格值中复制了它

Sub CutCopyValue()
Dim Last As Long
Dim i As Long
   Last = Cells(rows.Count, "A").End(xlUp).row
    For i = Last To 1 Step -1
        If Len(Cells(i, "A").Value) < 10 Then
            Cells(i, "A").Copy // I got lost in the destination
        End If
    Next i
End Sub   

感谢每一位帮助!

1 个答案:

答案 0 :(得分:2)

您使用.Copy无法使用&,只需使用字符串连接Sub CutCopyValue() Dim LastRow As Long Dim i As Long Dim DatSheet As Worksheet Set DatSheet = ActiveSheet With DatSheet LastRow = .Cells(.Rows.Count, "A").End(xlUp).Row For i = LastRow To 1 Step -1 If Len(.Cells(i, "A").Value) < 10 Then .Cells(i - 1, "A").Value = .Cells(i - 1, "A").Value & .Cells(i, "A").Value End If Next i End With 'DatSheet End Sub

SearchResponse