[英]Copy - Paste (iterating ) - Ms Excel - VBA
I'm new to writing codes in VB. 我是VB编写代码的新手。
Can somebody help me in writing a VBA code to copy and paste data from sheet 1 to sheet 2 with certain conditions. 有人可以帮我编写VBA代码,以便在一定条件下将数据从工作表1复制和粘贴到工作表2上。
Sheet 1 : Column ABC data to be copied 表格1:要复制的ABC列数据
Sheet 2 : 表格2:
Copied data to be pasted in Column A alone in sheet 2 复制的数据仅粘贴在工作表2的A列中
Final output be : 最终输出为:
A1, B1, C1 data to be pasted in A1, A2, A3 A2, B2, C2 data to be pasted in A4, A5, A6 And so on 粘贴到A1,A2,A3的A1,B1,C1数据粘贴到A4,A5,A6的A1,B1,C1数据
And a condition be, after copy and pasting all data, remove all empty rows. 并且条件是,在复制并粘贴所有数据之后,删除所有空行。
Try this Macro this macro copy data from sheet2 to sheet1 you can reverse it 试试这个宏,这个宏将数据从sheet2复制到sheet1,您可以将其反转
Option Explicit
Sub Creasy_copy()
Dim S1 As Worksheet, S2 As Worksheet
Dim Ro%, Col%, i%, j%, m%
Dim My_Rg As Range
Set S1 = Sheets("Sheet1")
Set S2 = Sheets("Sheet2")
Set My_Rg = S2.Range("a1").CurrentRegion
S1.Range("a1").CurrentRegion.ClearContents
m = 1
With My_Rg
Ro = .Rows.Count
Col = .Columns.Count
For i = 1 To Ro
For j = 1 To Col
If .Cells(i, j) <> vbNullString Then
S1.Cells(m, 1) = .Cells(i, j)
m = m + 1
End If
Next
Next
End With
End Sub
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.