Special Copy Method???

jadox

New Member
Joined
Feb 16, 2014
Messages
38
Hey guys,

I've got the code above, but the problem is that when I copy the cells it's copying the formulas and all the formatting too. How can I tweak it to only copy the values inside?

Thank you.


Code:
Sub cpydat()
Dim sh1 As Worksheet, sh2 As Worksheet, lr As Long, rng As Range, c As Range, fLoc As Range, grp As Range
Set sh1 = Sheets(1) 'Edit sheet name
Set sh2 = Sheets(2) 'Edit sheet name
lr = sh1.Cells(Rows.Count, 5).End(xlUp).Row
Set rng = sh1.Range("E2:E" & lr)
For Each c In rng
Set fLoc = sh2.Range("B:B").Find(c.Value, , xlValues)
If Not fLoc Is Nothing Then
Set grp = Union(fLoc.Offset(0, -1), fLoc.Offset(0, 1), fLoc.Offset(0, 2))
grp.Copy c.Offset(0, 3)
End If
Next
End Sub
 
Last edited:

Excel Facts

Create a chart in one keystroke
Select the data and press Alt+F1 to insert a default chart. You can change the default chart to any chart type
untested

grp.Copy c.Offset(0, 3).Value
 
Upvote 0
Maybe ...

Code:
            grp.Copy
            c.Offset(, 3).PasteSpecial Paste:=xlPasteValues
 
Upvote 0
Code:
c.Offset(,3).PasteSpecial Paste:=xlPasteValues

returns

Compile Error: Expected end of statement.

it's driving me crazy :(
 
Upvote 0
No compile error for me.
 
Upvote 0
Thanks Shg, solved it.

But now I'm having another issue: The find method that I use in the same code is not not working properly: with cells that contain text is ok but with those that contain numbers it doesn't make the difference between 1 and 17 or 2 and 29, (it's not case sensitive, I think). Can you help me with that too?

thanks!
 
Upvote 0
try

Code:
lr = sh1.Cells.Find("*", SearchOrder:=xlByRows, LookIn:=xlValues, SearchDirection:=xlPrevious).Row
 
Upvote 0
it's not working because the cell values are not in order. I could have something like this:

indexName 1Name2Name3Name4Value
1
2
3
4
5
6
10
11
12
13
21
22
23
24

<tbody>
</tbody>
sh1

indexName1Name2Name3Name4Value
2324
154234
4234
17234
2523
6856
11567
43456
6456
867
1934
2145
5656
534

<tbody>
</tbody>
sh2


I need to copy the values from sh2 from the column Value to the Column Value in sh1 but the index numbers in sh2 are scrambled so the code I have is not differentiating between 1 and 11 or 2 and 22 it copies the firs value whose index "matches" first, so going through the rows one by one is not a good solution.

Can anyone help please?
 
Upvote 0
the only fix attempted on your code is to provide the value of a cell, so as you say its not a good solution.

If you need something different you need to explain what you want to happen, and you expected results
 
Upvote 0

Forum statistics

Threads
1,215,381
Messages
6,124,615
Members
449,175
Latest member
Anniewonder

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