I'm new to writing codes in VB.
Can somebody help me in writing a VBA code to copy and paste data from sheet 1 to sheet 2 with certain conditions.
Sheet 1 : Column ABC data to be copied
Sheet 2 :
Copied data to be pasted in Column A alone in sheet 2
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
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
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
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.