Hi,
I am new to VBA and Macro.
I have a columnwise data, which I want to copy range of cells and paste values with certain criteria to specified cell using VBA.
My Data:
A B C D E F G H I J
1 1 1 2 3 3 4 5 6 7 7
2 2 2 3 4 4 5 6 7 8 8
3 3 3 4 5 5 6 7 8 9 9
4 4 4 5 6 6 7 8 9 0 0
5 5 5 6 7 7 8 9 0 1 1
What I am trying is if A1 and B1 is matching, then copy A1:B5 and paste it to cell A15, then goto next two columns i.e. C1 and D1, if C1 and D1 is matching then copy C1:D5 and paste it in C15 as it the blank cell after pasting data in A15.
If A1 and B1 is not matching, then copy only A1:A5 range and paste it to cell A30, then check B1 and C1 and repeat the process if it is matching/not matching till the last column with data.
I tried with the below code for two columns but not able to make out how to repeat the process further.
Sub Test()
If Range("A1") And Range("B1") = 1 Then
Range("A1:B5").Select
Selection.Copy
Range("A15").Select
ActiveCell.PasteSpecial xlPasteValues
Else
Range("A1:A5").Select
Selection.Copy
Range("A30").Select
ActiveSheet.PasteSpecial xlPasteValues
End If
End Sub
All your help will be much appreciated.
Thanks in advance.
Pradeep
Bookmarks