[英]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.