Conditional Paste using the VBA

luvbite38

Active Member
Joined
Jun 25, 2008
Messages
368
Hi,

I hope someone can help me out of here.

Using VBA

Can I copy a Range from Sheet called LookupLists (range = G2:G117). Where Cell G2 has a unique ID

And then go to Sheet called DATASHEET find the G2 value in row 1 of DATASHEET and paste (overwrite) the info as value in DATASHEET.

Kindest ever regards, :)

thanks thanks thanks for your time
 

Excel Facts

Excel Wisdom
Using a mouse in Excel is the work equivalent of wearing a lanyard when you first get to college
<font face=Courier New><SPAN style="color:#00007F">Sub</SPAN> Paste_LookupLists()<br><br>    <SPAN style="color:#00007F">Dim</SPAN> Found <SPAN style="color:#00007F">As</SPAN> Range, rngCopy <SPAN style="color:#00007F">As</SPAN> Range<br>    <br>    <SPAN style="color:#00007F">Set</SPAN> rngCopy = Sheets("LookupLists").Range("G2:G117")<br>    <SPAN style="color:#00007F">Set</SPAN> Found = Sheets("DATASHEET").Range("1:1").Find( _<br>                                What:=rngCopy(1).Value, _<br>                                LookIn:=xlValues, _<br>                                LookAt:=xlWhole, _<br>                                MatchCase:=False)<br>                        <br>    <SPAN style="color:#00007F">If</SPAN> <SPAN style="color:#00007F">Not</SPAN> Found <SPAN style="color:#00007F">Is</SPAN> <SPAN style="color:#00007F">Nothing</SPAN> <SPAN style="color:#00007F">Then</SPAN><br>        Found.Resize(rngCopy.Count).Value = rngCopy.Value<br>    <SPAN style="color:#00007F">Else</SPAN><br>        MsgBox "No match found for " & rngCopy(1).Value, vbExclamation, "No Match"<br>    <SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">If</SPAN><br>    <br><SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">Sub</SPAN></FONT>
 
Upvote 0
try this

<Code>
Sub CopyRange()
Dim dblTarget As Double
Dim cFound As Range

'find the value to find
dblTarget = Sheets("LookupLists").Range("G2")

'find the value on sheet DATASHEET
Set cFound = Sheets("DATASHEET").Range("a1").EntireRow.Find(dblTarget)
If Not cFound Is Nothing Then
'copy over the data
Sheets("LookupLists").Range("G2:G117").Copy
Sheets("DATASHEET").Activate
cFound.PasteSpecial xlValues
Else
MsgBox "Data not found"
End If
End Sub
<Code>
 
Upvote 0
You guys are super amazing..... May God bless you with a free Iphone 4s.......

THANKS THANKS THANKS A MILLION
 
Upvote 0
hey guys,

if possible, can the above provided code be slightly tweaked?

everything is same but I need to find the values in column A now and paste the range transpose.

any suggestion will be much appreciated.

Thank in advance
 
Upvote 0

Forum statistics

Threads
1,224,597
Messages
6,179,808
Members
452,944
Latest member
2558216095

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