Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/excel/24.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Excel 将值从列B剪切并粘贴到下一个空行列A_Excel - Fatal编程技术网

Excel 将值从列B剪切并粘贴到下一个空行列A

Excel 将值从列B剪切并粘贴到下一个空行列A,excel,Excel,我想将一个值从B 444列剪切到rr下a列的下一个空行。然后脚本将循环通过B列,因此16将粘贴在ee等下面 我使用以下代码查找A列中的下一个空行,但需要更多帮助来构建脚本 lastrow=Sheets1.RangeA1.EndxlDown.Row+1 任何帮助都将不胜感激您需要的是以下内容: Sub CutValuesColumnBtoA() Dim copyCell As Range Dim colB As Range Dim lastRowColB As Long Dim firstBla

我想将一个值从B 444列剪切到rr下a列的下一个空行。然后脚本将循环通过B列,因此16将粘贴在ee等下面

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

lastrow=Sheets1.RangeA1.EndxlDown.Row+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