简体   繁体   English

VBA从活动行复制某些列,如果单元格值多次复制并粘贴

[英]VBA to copy certain column from active row, copy and paste if cell value multiple times

enter image description here enter image description here I am a newbie to VBA.在此处输入图像描述 在此处输入图像描述我是 VBA 的新手。 I want Excel to (1) copy cells A:Z of the active row, (2) insert one row below the active row, and paste the values of the recently copied cells into the new blank row.我希望 Excel (1) 复制活动行的单元格 A:Z,(2) 在活动行下方插入一行,并将最近复制的单元格的值粘贴到新的空白行中。

i have two different values in B Column, then I make two lines same value and update B cell value in second values我在 B 列中有两个不同的值,然后我将两行设为相同的值并在第二个值中更新 B 单元格值

enter image description here在此处输入图像描述

I will appreciate being taught how to only copy certain cells of active row to paste below.我会很感激被教导如何只复制活动行的某些单元格以粘贴到下面。 Thank you.谢谢你。

Sub CopyInsertPaste()

Dim Rng As Range
Dim RowNum As Integer

RowNum = ActiveCell.Row

Set Rng = Range("A" & RowNum & ":Z" & RowNum)

With Rng
    .Offset(1, 0).EntireRow.Insert
    .Copy Range("A" & RowNum + 1)
End With

Dim BCell1 As Range
Set BCell1 = Range("B" & RowNum)

Dim BCell2 As Range
Set BCell2 = Range("B" & RowNum + 1)

    If InStr(BCell1.Value, ",") Then
        Dim Text1 As String
        Text1 = Left(BCell1.Value, InStr(1, BCell1.Value, ",") - 1)
        BCell1.Value = Text1
                
        Dim index As Integer
        index = InStr(1, BCell2.Value, ",")
        
        Dim Text2 As String
        Text2 = Right(BCell2.Value, Len(BCell2.Value) - index)
        BCell2.Value = Text2
    End If

End Sub

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 复制/粘贴行 n 次(根据单元格中的值) - copy/paste row n number of times (according to value from cell) Excel VBA从列复制值并将值粘贴到单元格中 - excel vba copy value from a column and paste value in a cell 将单元格值复制并粘贴到列的最后一行 - Copy and paste a cell value on the last row of a column VBA excel:复制整行并根据特定单元格值多次粘贴。 然后对下面的下一行执行相同的任务 - VBA excel : Copy Entire Row and paste above multiple times based on specific cell value. Then perform same task for next rows below VBA Excel:宏,该宏在一行中搜索特定单元格中的某个变量值,然后将值复制并粘贴到此列中 - VBA Excel : Macro that searches a row for a certain variable value from specific cell and then copy&pastes value to this column Excel VBA 自动根据单元格值复制整行“X”次并粘贴到单独的工作表中 - Excel VBA automation copy entire row “X” times based on cell value and paste in separate sheet 复制粘贴循环多次作为单元格值-VBA - Copy paste loop a number of times as the cell value - VBA Excel VBA宏可根据列中的文本将单元格值复制并粘贴到某些单元格 - Excel VBA Macros to copy and paste cell value to certain cells based on text in column 复制并粘贴该行N次(N取决于单元格中的值) - Copy and paste the row a N number of times (N based on a value in the cell) 复制行并粘贴X次,具体取决于单元格值 - Copy Row and paste X amount of times dependent on cell value
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM