Macro to find cell address and copy data to that cell

quietfranklin

New Member
Joined
Jun 18, 2017
Messages
1
I have to copy cells from a report spreadsheet into a master and where they go is determined by three different identifiers; DOCNBR, STNDDOCNBR and ACRN. So, I used CELL,"address",INDEX,MATCH to find the cell address where the information should go in the master. Then I used this macro to copy the data over


Sub foobar()
Dim srng As Range, dws As Worksheet
Dim k As Long, sccol As Long, socol As Long, lcol As Long, dccol As Long, docol As Long
Set srng = ActiveCell.CurrentRegion
Set dws = Windows("Master Unshipped Expired.xlsx").ActiveSheet
With Application.WorksheetFunction
sccol = .Match("REMARKS", srng.Rows(1), 0)
lcol = .Match("Location", srng.Rows(1), 0)
dccol = .Match("April 2017 Remarks", dws.Rows(1), 0)

End With

For k = 2 To srng.Columns.Count
If Not IsEmpty(srng.Cells(k, lcol).Value) Then




MsgBox Prompt:=">" & srng.Cells(k, lcol).Value & "<"

With dws.Range(srng.Cells(k, lcol).Value).EntireRow
srng.Cells(k, sccol).Copy Destination:=.Cells(1, dccol)

End With

End If
Next k
End Sub




This is what the report looks like

DOCNBR STNDDOCNBR ACRN REMARKS LOCATION
PKUA434 N0038314GM801 AA Shipped Z252
PMFF453 N0001917WX001 ABUnbilled Z809
PKUAE45 N0042115G0003 BCNo shippingZ25

<tbody>
</tbody>


And this is what the master looks like

DOCNBR
STNDDOCNBR
ACRN
April 2017 Remarks
PKUA434N0038314GM801 AA
PMFF453 N0001917WX001 AB
PKUAE45 N0042115G0003 BC

<tbody>
</tbody>


Is there any way I could trim the fat and just make the macro find where the data needs to go?
 

Excel Facts

Workdays for a market open Mon, Wed, Friday?
Yes! Use "0101011" for the weekend argument in NETWORKDAYS.INTL or WORKDAY.INTL. The 7 digits start on Monday. 1 means it is a weekend.

Forum statistics

Threads
1,215,767
Messages
6,126,767
Members
449,336
Latest member
p17tootie

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top