簡體   English   中英

VBA從活動行復制某些列,如果單元格值多次復制並粘貼

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

在此處輸入圖像描述 在此處輸入圖像描述我是 VBA 的新手。 我希望 Excel (1) 復制活動行的單元格 A:Z,(2) 在活動行下方插入一行,並將最近復制的單元格的值粘貼到新的空白行中。

我在 B 列中有兩個不同的值,然后我將兩行設為相同的值並在第二個值中更新 B 單元格值

在此處輸入圖像描述

我會很感激被教導如何只復制活動行的某些單元格以粘貼到下面。 謝謝你。

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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM