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

Add Bullets to Range
Select range. Press Ctrl+1. On Number tab, choose Custom. Type Alt+7 then space then @ sign (using 7 on numeric keypad)
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,216,100
Messages
6,128,834
Members
449,471
Latest member
lachbee

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