【问题标题】:Cut and Paste value from Column B to next empty row Column A将 B 列中的值剪切并粘贴到下一个空行 A 列
【发布时间】:2018-07-15 06:26:15
【问题描述】:

我想将 B 列 (444) 中的一个值剪切到 A 列中的下一个空行(在 rr 下)。然后脚本将遍历 B 列,因此 16 将粘贴在 ee 等下

我使用以下代码在 A 列中找到下一个空白行,但需要更多帮助来构建脚本;

lastrow = Sheets(1).Range("A1").End(xlDown).Row + 1

任何帮助将不胜感激

【问题讨论】:

    标签: excel


    【解决方案1】:

    你需要的是这样的:

    Sub CutValuesColumnBtoA()
    
    Dim copyCell As Range
    Dim colB As Range
    Dim lastRowColB As Long
    Dim firstBlankRowColA As Long
    
    'get the rownumber of the last non-empty cell in column B
    lastRowColB = Cells(Rows.Count, 2).End(xlUp).Row
    
    'get the range thats holds the values to be cut&pasted from column B
    Set colB = Range(Cells(1, 2), Cells(lastRowColB, 2))
    
    'loop through the values in colB.
    'If not empty then paste to first empty cell in column A
    For Each copyCell In colB
    
        If copyCell <> "" Then
    
            'get the rownumber of the first blank cell in column A
            'Cells(1, 1).End(xlDown).Row will not work if one or both of the 
            'first two rows are empty, so they need to be tested separatly
            If Cells(1, 1) = "" Then
                firstBlankRowColA = 1
            ElseIf Cells(2, 1) = "" Then
                firstBlankRowColA = 2
            Else
                firstBlankRowColA = Cells(1, 1).End(xlDown).Row + 1
            End If
    
        Cells(firstBlankRowColA, 1).Value = copyCell
    
        End If
    
    Next copyCell
    
    'clear colB Range, because this is a cut action (and not copy)
    colB.ClearContents
    
    End Sub
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-08-18
      • 1970-01-01
      • 1970-01-01
      • 2019-06-01
      • 2017-07-09
      • 2018-12-11
      相关资源
      最近更新 更多