Quantcast
Channel: Excel Help Forum - Excel Programming / VBA / Macros
Viewing all articles
Browse latest Browse all 50049

Need advise to revise some code to copy data from one workbook to another.

$
0
0
Code:

Sub MainMacro()
Dim ws As Worksheet:    Set ws = Sheets("Sheet1")
Dim wb As Workbook:    Set wb = Workbooks("Received.xlsm")
Dim wksht As Worksheet
Dim lastrow As Long, icell As Long
Dim sNum As String, sItem As String

lastrow = ws.Range("C" & Rows.Count).End(xlUp).Row

For icell = 2 To lastrow
    If Not ws.Range("C" & icell) Is Nothing Then
        sNum = ws.Range("C" & icell).Offset(0, -2).Value
        sItem = ws.Range("C" & icell).Offset(0, -1).Value
        For Each wksht In wb.Worksheets
            If wksht.Name = sNum Then
                wksht.Range("C1").End(xlDown).Offset(1, 0).Value = sItem
            End If
        Next wksht
    End If
Next icell

End Sub

I have the above code and it works great for pasting data into a cell on another worksheet. However, I need help modifying it...I need to copy data from column C, then based on data in column A and B, find the matching record on a different workbook and paste to the first blank cell for that specific record.

Ideas???
Attached Files

Viewing all articles
Browse latest Browse all 50049

Trending Articles