L
Legacy 316950
Guest
Hello everybordy,
I am new on VBA and I am tryng to copy specifc values from Sheet2 to Sheet1, but i don't know how to concatenate this values and how to copy the right values.
My code copies but it's not working as i was expecting.
Here is my code.
This is my destination worksheet
<tbody>
</tbody>
<tbody>
</tbody> My source worksheet that's where i'm copying from.
If anyone have an idea to give me i will be very grateful.
I use Windows Seven,Office 2010. here it's a link with my file .xlsm https://www.dropbox.com/s/mirzp11rk5ebad5/copy from other worksheet.xlsm?dl=0
Thanks and Hava a Nice Day!
I am new on VBA and I am tryng to copy specifc values from Sheet2 to Sheet1, but i don't know how to concatenate this values and how to copy the right values.
My code copies but it's not working as i was expecting.
Here is my code.
Code:
Sub copyvalues()
'Declaration of variables
Dim lastRowDestination As Long
Dim lastrowSource As Long
Dim wsDestination As Worksheet
Dim wsSource As Worksheet
Dim b As Range
Dim c As Range
'Setting worksheets
Set wsDestination = Sheets("Sheet1")
Set wsSource = Sheets("Sheet2")
'Counting the last row of wsSource worksheet
With ActiveWorkbook.Sheets("Sheet1").Activate
lastrowSource = Range("A" & Rows.Count).End(xlUp).Row
End With
'Counting the last row of wsDestination worksheet
With ActiveWorkbook.Sheets("Sheet2").Activate
lastRowDestination = Range("A" & Rows.Count).End(xlUp).Row
End With
'The Idea of this for is to hold one value of wsSource to compare with all values from wsSource, if the values of the
'are equal then I copy from the source and paste into the wsDestination.
With wsDestination
.Activate
For Each c In Range("A2:A" & lastRowDestination)
Set b = wsSource.Columns(2)
For Each b In Range("A2:A" & lastrowSource)
If c = b Then
.Cells(c.Row, 2).Value = wsSource.Cells(b.Row, 2).Offset(rowoffset:=1, columnoffset:=0).Value
End If
Next b
Next c
End With
End Sub
This is my destination worksheet
Product | What I have | What I was expecting | |||
<colgroup><col width="121"></colgroup><tbody> </tbody> |
<colgroup><col width="141"></colgroup><tbody> </tbody> | 16,17 | |||
<colgroup><col width="121"></colgroup><tbody> </tbody> |
<colgroup><col width="141"></colgroup><tbody> </tbody> |
<colgroup><col width="141"></colgroup><tbody> </tbody> | |||
<tbody>
</tbody>
<colgroup><col></colgroup><tbody> </tbody> |
<colgroup><col></colgroup><tbody> </tbody> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
<tbody>
</tbody>
If anyone have an idea to give me i will be very grateful.
I use Windows Seven,Office 2010. here it's a link with my file .xlsm https://www.dropbox.com/s/mirzp11rk5ebad5/copy from other worksheet.xlsm?dl=0
Thanks and Hava a Nice Day!