PDA

View Full Version : How to amend this code in order to copy the inserted comment also?



squippe
01-31-2017, 05:12 AM
This code works great except it ignores the inserted comment in the cell. How to amend the code in order to copy the text & the comment?



Sub vertailu()

Dim lastRow1 As Long
Dim lastRow2 As Long
Dim tempVal As String

lastRow1 = Sheets("11").Range("K" & Rows.Count).End(xlUp).Row
lastRow2 = Sheets("12").Range("K" & Rows.Count).End(xlUp).Row

For sRow = 2 To lastRow1
tempVal = Sheets("11").Cells(sRow, "K").Text
For tRow = 2 To lastRow2
If Sheets("12").Cells(tRow, "K") = tempVal Then
Sheets("12").Cells(tRow, "O") = Sheets("11").Cells(sRow, "O")
End If
Next tRow
Next sRow


Dim match As Boolean

'now if no match was found, then put NO MATCH in cell
For lRow = 2 To lastRow2
match = False
tempVal = Sheets("12").Cells(lRow, "K").Text

For sRow = 2 To lastRow1
If Sheets("11").Cells(sRow, "K") = tempVal Then
match = True
End If
Next sRow

If match = False Then
Sheets("12").Cells(lRow, "O") = "NO MATCH"
End If
Next lRow
End Sub

mana
01-31-2017, 06:03 AM
Sheets("11").Cells(sRow, "O").Copy Sheets("12").Cells(tRow, "O")

squippe
01-31-2017, 06:11 AM
Please specify what part I should replace with the given code?

mana
01-31-2017, 06:16 AM
Sheets("12").Cells(tRow, "O") = Sheets("11").Cells(sRow, "O")

mana
01-31-2017, 06:17 AM
Option Explicit


Sub vertailu2()
Dim lastRow1 As Long
Dim lastRow2 As Long
Dim tempVal As String
Dim sRow As Long, tRow As Long
Dim IsMatch As Boolean

lastRow1 = Sheets("11").Range("K" & Rows.Count).End(xlUp).Row
lastRow2 = Sheets("12").Range("K" & Rows.Count).End(xlUp).Row

For tRow = 2 To lastRow2
IsMatch = False
For sRow = 2 To lastRow1
tempVal = Sheets("11").Cells(sRow, "K").Text
If Sheets("12").Cells(tRow, "K") = tempVal Then
Sheets("11").Cells(sRow, "O").Copy Sheets("12").Cells(tRow, "O")
IsMatch = True
Exit For
End If
Next sRow
If IsMatch = False Then
Sheets("12").Cells(tRow, "O") = "NO MATCH"
End If
Next tRow

End Sub

squippe
01-31-2017, 07:05 AM
Great, you are my hero. thanks!

Next challenge:

I would like to concatenate A2 + C2 into K2 cell and repeat it on each row (and sheet) where I have data (a3 + c3= K3 and so on...)