Simple Copy/Paste Question

nburaq

Board Regular
Joined
Apr 2, 2021
Messages
220
Office Version
  1. 365
  2. 2019
Platform
  1. Windows
Hi Gents,
I would like to copy a range of data and paste into another column without overwriting the existing data. Normally, what I do is I copy the range of data and when I am pasting it I choose "paste special" and then click "skip blanks" this way works but in long range of data when I do this it overwrites the existing data always so maybe the empty cells are actually not empty? I don't know is there any way to paste this data with VBA or any other method? Thanks for the help and solution! PS: my scenario look like the screenshot below
copy_paste.png
 

Excel Facts

Will the fill handle fill 1, 2, 3?
Yes! Type 1 in a cell. Hold down Ctrl while you drag the fill handle.
How about
VBA Code:
Sub nburaq()
   With Range("A2:A" & Range("B" & Rows.Count).End(xlUp).Row)
      .Value = Evaluate(Replace(Replace("if(@<>"""",@,if(#<>"""",#,""""))", "@", .Address), "#", .Offset(, 4).Address))
   End With
End Sub
 
Upvote 0
Solution
How about
VBA Code:
Sub nburaq()
   With Range("A2:A" & Range("B" & Rows.Count).End(xlUp).Row)
      .Value = Evaluate(Replace(Replace("if(@<>"""",@,if(#<>"""",#,""""))", "@", .Address), "#", .Offset(, 4).Address))
   End With
End Sub
Hi Fluff,
You do your magic again hee :) it works like a charm! but one question if my paste value is starting from A1 then formula should be like this Range ("A1:A & ......... end Offset(, 4) indicates column to be copied right? In case it is not column E but F then it will be Offset(, 5)? Thanks again for your help and patience!
 
Upvote 0
That's right. :)
I tried the same formula but this time giving offset value as Offset(, -5) for another worksheet but it showed me debugging error in this line so can I use this for general purpose or it was only for this sample? Thanks again
VBA Code:
.Value = Evaluate(Replace(Replace("if(@<>"""",@,if(#<>"""",#,""""))", "@", .Address), "#", .Offset(, -5).Address))
 
Upvote 0
Is that still working on col A? If so you cannot offset 5 columns to the left of col A
 
Upvote 0
Is that still working on col A? If so you cannot offset 5 columns to the left of col A
Actually this time ranges were different to be copied and pasted here how I modified to another scenario
VBA Code:
Sub nburaq()
   With Range("G2:G" & Range("H" & Rows.Count).End(xlUp).Row)
      .Value = Evaluate(Replace(Replace("if(@<>"""",@,if(#<>"""",#,""""))", "@", .Address), "#", .Offset(, -7).Address))
   End With
End Sub
 
Upvote 0
As column G is column 7 you cannot go 7 columns to the left as that would be col 0
 
Upvote 0
No Col A is col 1 not 0.
Offset( ,-1) is one column to the left of the col it's working on, so for col G that would mean col F
 
Upvote 0

Forum statistics

Threads
1,214,785
Messages
6,121,543
Members
449,038
Latest member
Guest1337

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