Copy cell of two column only if both cell are not blank in another two column

MelissaSx

New Member
Joined
Feb 16, 2018
Messages
2
I have a excel sheets like this:
Code:
A  B      C   D
1          2   3
            4   5
2  3      3   4
4  5
1
           
1
    3
3  4

I should copy the column A and B in CD like as the example.
Copy only both cells contigous if not both empty. In the real sheet in column a there is a question and in the column B there is the correspondent response.
I search a VBA code to make this.
 

Excel Facts

Did you know Excel offers Filter by Selection?
Add the AutoFilter icon to the Quick Access Toolbar. Select a cell containing Apple, click AutoFilter, and you will get all rows with Apple
Hi & welcome to the board
How about
Code:
Sub CopyPairs()
   Dim Rng As Range
   For Each Rng In Range("A1", Range("A" & Rows.Count).End(xlUp))
      If Rng <> "" And Rng.Offset(, 1) <> "" Then
         Rng.Resize(, 2).Copy Range("C" & Rows.Count).End(xlUp).Offset(1)
      End If
   Next Rng
End Sub
 
Upvote 0
Hi & welcome to the board
How about
Code:
Sub CopyPairs()
   Dim Rng As Range
   For Each Rng In Range("A1", Range("A" & Rows.Count).End(xlUp))
      If Rng <> "" And Rng.Offset(, 1) <> "" Then
         Rng.Resize(, 2).Copy Range("C" & Rows.Count).End(xlUp).Offset(1)
      End If
   Next Rng
End Sub

Thanks, i make manually a try with my pen, because i have to install the excel again, but i think it works. And thanks beacuse i learned how use some function i didn't knew.
I'll try with VBA when i have the program. :)
 
Upvote 0

Forum statistics

Threads
1,215,503
Messages
6,125,175
Members
449,212
Latest member
kenmaldonado

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top