VBA to Copy Selected Cells

purceld2

Well-known Member
Joined
Aug 18, 2005
Messages
586
Office Version
  1. 2013
Platform
  1. Windows
Hi There
I have looked on the internet and cannot seem to find an example of VBA copy code to do what I require.

Background

I get numerous orders sent to me on a daily basis via email which I currently manually cut and paste the relevant data into a weekly Excel spreadsheet for management. This work is very tedious and I am trying to automate the process.

I have cut and paste the table from the email into a sheet call InOrder. Now I need to get the data into the report (Financial). I have attached of the two sheets and if somebody can get me going I would be most grateful.

Another issues I have is that subsequent orders need to be added to the next free column.

Only data from InOrder that has a corresponding name needs in Financail sheet needs be copied

Thanks you in advance for any help


Excel 2010
ABCDE
1Weekly Report
2
3Tuesday 28 October 2014
4
5Job Number
6Date Booked
7Sales Person
8Advertiser
9Product
10Network(s)
11Agency
12Specialist
13Sales Agent
14Barter
15Agency Commission
16Over-rider
17Sales Agent Commission
18Barter Company Commission
19Category
20Stocked Product
21
22Gross Media Spend*
23Gross Research
24Agency Commission on Research Y/N
25Gross Production
26Agency Commission on Production Y/N
27Screens (No)
28Playout (Days)
29Start Date Date
30End Date Date
Financial




Excel 2010
AB
1AgencyMEC
2SpecialistZone
3AdvertiserTest
4ProductTest 2
5Start date22/12/2014
6End date18/01/2015
7Network(s)Forecourt
8Regionality
9Screens (No)3
10Gross Media Spend£2,000
11Conditions of booking
12Barter Agency
13Agency Commission15%
14Specialist Comms5%
15Barter%
16Additional Comms%
17Over Rider13%
18Amscreen Net Net Net
19Booking Reference82738
20Creative Agency
21Creative Contact
22CategoryRetail
23Sales PersonSara Froud
InOrder
 

Excel Facts

What is =ROMAN(40) in Excel?
The Roman numeral for 40 is XL. Bill "MrExcel" Jelen's 40th book was called MrExcel XL.
Is this question still relevant? I understand that you have a number of sheets like 'InOrder' and you want to transfer the relevant information to the Financial sheet, each in a new column.
 
Upvote 0
Yes, if you have a solution, it would be most helpful

Regards
 
Upvote 0
Code:
Option Explicit


Sub TransferAgencyDetails()
    Dim wsF As Worksheet, wsIO As Worksheet
    Dim rIn As Range, rOut As Range, rFound As Range
    Dim lRIn As Long, lCOut As Long
    
    Set wsF = ThisWorkbook.Sheets("Financial")
    Set wsIO = ThisWorkbook.Sheets("InOrder")
    
    Set rIn = wsIO.Range("A1")      ' 1st cell of input table
    Set rOut = wsF.Range("A1")      ' 1st cell of column in output table holding the titles
    lCOut = wsF.Range("A5").CurrentRegion.Columns.Count ' count the number of columns populated
    
    Do While rIn.Value <> vbNullString  ' assuming no gaps in column 1 of the input table
        ' find the current title of the input tble in the output table
        Set rFound = rOut.EntireColumn.Find(what:=rIn.Value, _
                        after:=Cells(Cells.Rows.Count, 1), _
                        LookIn:=xlValues, lookat:=xlWhole, _
                        searchdirection:=xlNext, MatchCase:=False)
        If Not rFound Is Nothing Then       ' key word is found
            ' copy the value to the coressponding column in the output table
            rOut.Offset(rFound.Row - 1, lCOut).Value = rIn.Offset(0, 1).Value
        End If
        
        Set rIn = rIn.Offset(1, 0)  ' move one cell down in the input table
    Loop    'rIn.Value
    
End Sub
 
Upvote 0

Forum statistics

Threads
1,222,580
Messages
6,166,880
Members
452,080
Latest member
Akin Himself

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