PDA

View Full Version : Comparing two columns in different sheet



Swetha_Moni
12-03-2012, 09:50 PM
Hi
i am new to vbscript.i'm trying to compare two columns column A in Wrkbk1 & column A in wrkbk 2 &the result should be if the strings in the column matches the result of column C in wrkbk2 should be copied to column C in wrkbk1.i have tried with this code and facing object required error..Can anyone help me
Dim c2 As Range, c As Range
' Set w1 = Workbooks.Open("D:\SM\SM.xlsm")
Set W1 = ActiveWorkbook
Set W2 = Workbooks.Open("D:\RIP\RipAnalysis.xlsm")
With W1.Worksheets("Sheet4") 'Object required error
For Each c2 In W1.Range("A1:A" & .Cells(Rows.Count, 1).End(xlUp).Row)
Set c = W2.Sheets("TotalCounts").Columns(1).Find(c2, , xlValues, xlWhole)
If Not c Is Nothing Then
c2.offet(, 2).Copy W2.Sheets("TotalCounts").Range("C" & Rows.Count).End(xlUp).Offset(1)
End If
Next c2
End With
End Sub

Thanks

mohanvijay
12-03-2012, 11:25 PM
That means in W1 workbook there is no sheet in tha name "Sheet4".

You may use functions for your task

Swetha_Moni
12-04-2012, 01:54 AM
at sheet is existing in dat excel sheet
nw i'm getting error n dis function

For Each c2 In W1.Range("A1:A" & .Cells(Rows.Count, 1).End(xlUp).Row)
Set c = W2.Sheets("TotalCounts").Columns(1).Find(c2, , xlValues, xlWhole)
If Not c Is Nothing Then
c2.offet(, 2).Copy W2.Sheets("TotalCounts").Range("C" & Rows.Count).End(xlUp).Offset(1)
End If
can anyone check nd say this function s correct..

the variable c is not getting the values form the column