Quantcast
Channel: Active questions tagged excel - Stack Overflow
Viewing all articles
Browse latest Browse all 89086

Copy data Using Vba, Match function

$
0
0

i am a new coder. Just a beginner in vba, and would like some help to solve this. i know i can use normal excel formulas but this is for learning. here is my code so far:

Sub matchpart()
Dim ocell As Range
Dim swb As Workbook
Dim sws As Worksheet, dws As Worksheet
Dim stext As String
Dim iRow As Long
Dim nxtRow As Long


Set swb = ActiveWorkbook
Set sws = swb.Sheets("sheet1")
Set dws = swb.Sheets("sheet2")

For Each ocell In dws.Range("FILE_NAMES")
    stext = Left(ocell.Value, 12)
On Error Resume Next
iRow = Application.WorksheetFunction.Match(stext, sws.Range("ID_NUMBER"), 0)
On Error GoTo 0
    If iRow > 0 Then
       Application.Index (Range("ID_PARENT").Copy)
    Else
        ocell.Offset(0, 1) = ""
        End If
        Next

MsgBox ("Done")
End Sub

my task is to match 1 column from sheet 2 (ID_NUMBER) with 1 column sheet 1 (FILE_NAMES). after this copy the corresponding value in the next column in sheet 1 (which has been matched) and paste it into the next column in sheet 2.

here is my data as an e.g sheet1:

ID_PARENT     ID_NUMBER 
pan               3
same              2
kappa             1
lame              5
dame              5

sheet 2:

FILE_NAMES      BPM_LIST
1                   
5
3
2
4
5

thus would like to match and copy in to BPM_LIST using my code.


Viewing all articles
Browse latest Browse all 89086

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>