ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   copy but don't overlay (https://www.excelbanter.com/excel-programming/331886-copy-but-dont-overlay.html)

mwc0914

copy but don't overlay
 

Is there a way via a macro to copy the values in a range of cells t
another range of cells, but if there is anything in the destinatio
range of cells, do not overlay with the values you are copying from?

Consolidating would work, except I would need my destination cell rang
to be one of the consolidation cell ranges

--
mwc091
-----------------------------------------------------------------------
mwc0914's Profile: http://www.excelforum.com/member.php...fo&userid=2413
View this thread: http://www.excelforum.com/showthread.php?threadid=37943


tkstock[_16_]

copy but don't overlay
 

Code:
--------------------
Dim rng1 As Range
Dim rng2 As Range
Set rng1 = Range("A1:B50") ' Your copy range
Set rng2 = Range("C1:D50") ' Your paste range
For Each x In rng2.Cells
If x.Value < "" Then Exit Sub
Next x
rng1.Copy
rng2.PasteSpecial xlPasteAll
--------------------


HTH


--
tkstock


------------------------------------------------------------------------
tkstock's Profile: http://www.excelforum.com/member.php...o&userid=14443
View this thread: http://www.excelforum.com/showthread...hreadid=379439


mwc0914[_2_]

copy but don't overlay
 

Thanks, but it did not work.

I have attached an example spreadsheet with the macro in it. Maybe I a
missing something. I want to be able to copy cells E1:G3 to A1:C3 bu
not overlay what is already in cell A1:C1

+-------------------------------------------------------------------
|Filename: example.zip
|Download: http://www.excelforum.com/attachment.php?postid=3504
+-------------------------------------------------------------------

--
mwc091
-----------------------------------------------------------------------
mwc0914's Profile: http://www.excelforum.com/member.php...fo&userid=2413
View this thread: http://www.excelforum.com/showthread.php?threadid=37943


tkstock[_17_]

copy but don't overlay
 

Code:
--------------------
Dim rng1 As Range
Dim rng2 As Range
Set rng1 = Range("e1:g3") ' Your copy range
Set rng2 = Range("a1:c3") ' Your paste range
r1 = rng1.Rows.Count
c1 = rng1.Columns.Count

For i = 1 To r1
For j = 1 To c1
If rng2.Cells(i, j) = "" Then
rng2.Cells(i, j) = rng1.Cells(i, j)
End If
Next j
Next i
--------------------


That work for you? I thought if your paste range contained ANYTHING
you didn't want to paste anything. If you are just filling in, this
should work.


--
tkstock


------------------------------------------------------------------------
tkstock's Profile: http://www.excelforum.com/member.php...o&userid=14443
View this thread: http://www.excelforum.com/showthread...hreadid=379439


mwc0914[_3_]

copy but don't overlay
 

Got it....many thank

--
mwc091
-----------------------------------------------------------------------
mwc0914's Profile: http://www.excelforum.com/member.php...fo&userid=2413
View this thread: http://www.excelforum.com/showthread.php?threadid=37943



All times are GMT +1. The time now is 04:24 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com