![]() |
![]() |
|
|||||||
| Excel Questions All Excel/VBA questions - formulas, macros, pivot tables, general help, etc. Please post to this forum in English only. |
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Board Regular
Join Date: May 2002
Posts: 251
|
Hi,
Is there any way that you can macth values. for example I have 2 sheets. in both sheets column A information is same. now I want to crate a macro, if sheet1 column A text matches in Sheet2 cloumn A then copy cell value from Column M from sheet1 and paste in Sheet2 column P. Please help me with that. Thanks |
|
|
|
|
|
#2 |
|
Board Regular
Join Date: Apr 2002
Location: Greenwood, SC
Posts: 677
|
I know most folks here like to use range objects, but I am so much happier with the cells array...
Here is something that should work. If you need to copy more than just the value (i.e. formatting), you will need to change the .Cells(i, 16).Value = Cells(i, 13).Value to a copy/paste function. Sub MoveEm() Dim i As Long Dim iFirst As Long Dim Sheet1Name As String Dim Sheet2Name As String ' ' Define local variables ' Sheet1Name = "Sheet1" 'First Sheet Name Sheet2Name = "Sheet2" 'Second Sheet Name iFirst = 2 'Starting row Sheets(Sheet1Name).Select With Sheets(Sheet2Name) For i = iFirst To 65000 If Cells(i, 1).Value = "" Then Exit For 'Exit loop on first blank cell If Cells(i, 1).Value = .Cells(i, 1).Value Then 'If row A equal, .Cells(i, 16).Value = Cells(i, 13).Value 'Set row P = row M End If Next End With End Sub Good luck, K |
|
|
|
![]() |
| Bookmarks |
| Thread Tools | |
| Display Modes | |
|
|