+ Reply to Thread
Results 1 to 13 of 13

VBA copy and paste with criteria and different sheets

  1. #1
    Registered User
    Join Date
    11-02-2018
    Location
    London
    MS-Off Ver
    2007
    Posts
    6

    VBA copy and paste with criteria and different sheets

    Hello everyone,


    I am a beginner in VBA and I try to learn because I have a lot of reporting that I would like to automate.


    I would like to know if it is possible to help me on the construction of a macro.


    For a reporting, I import the data that will be on the sheet "source data".
    I would now like to take the data and put it according to criteria on the "control" sheet.
    So first in "Source Data", I only select the lines or appear "103" in column A:
    - I copy all the data from the sheet "Source data" and sheet "total" to the sheet "Control" and start from box C10 and continue until all lines 103 have not been all copy glue .
    Column C ("Source data") to / from "C10" ("Control").
    Column E ("Source data") to / from "D10" ("Control").
    Column M ("Source data") to / from "E10" ("Control").
    Column M ("Source data") to / from "E10" ("Control").
    Column I ("Total") to / from "G10" ("Control").
    Column R ("Source data") to / from "H10" ("Control").
    Column T ("Source data") to / from "I10" ("Control").
    Q column ("Source data") to / from "J10" ("Control").
    "K10" = ((H10 * G10) / 100) / I10
    "L10" = ((J10-K10) / J10) - Set Percent.
    Column F ("Control") from F10 = according to D10 (code) we will go to column B ("total") and if ya match we take the result in column C (name).
    We redo and copied to the last line where there are 103 in the sheet "Donnee Source".


    I left 2 lines in the "control" sheet to show the result.
    Attached Files Attached Files

  2. #2
    Valued Forum Contributor
    Join Date
    11-28-2015
    Location
    indo
    MS-Off Ver
    2016 64 bitt
    Posts
    1,256

    Re: VBA copy and paste with criteria and different sheets

    sokour try this
    Please Login or Register  to view this content.
    Last edited by daboho; 11-05-2018 at 06:48 AM.
    "ThankyouFor Attention * And Your Help!!"

  3. #3
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,516

    Re: VBA copy and paste with criteria and different sheets

    sokour,

    You need to check your formula in Col.K & L in bold.
    Please Login or Register  to view this content.
    Attached Files Attached Files

  4. #4
    Registered User
    Join Date
    11-02-2018
    Location
    London
    MS-Off Ver
    2007
    Posts
    6

    Re: VBA copy and paste with criteria and different sheets

    Thanks for the reply,

    But its a little bit complicated for a beginner like me

    why this part : Set cn = CreateObject("ADODB.Connection")
    Set rs = CreateObject("ADODB.Recordset")
    With cn
    .Provider = "Microsoft.Jet.OLEDB.4.0"
    .Properties("Extended Properties") = "Excel 8.0;HDR=No;"
    .Open ThisWorkbook.FullName
    End With

    Thank you can we simplify ?

  5. #5
    Valued Forum Contributor
    Join Date
    11-28-2015
    Location
    indo
    MS-Off Ver
    2016 64 bitt
    Posts
    1,256
    Quote Originally Posted by sokour View Post
    Thanks for the reply,

    But its a little bit complicated for a beginner like me

    why this part : Set cn = CreateObject("ADODB.Connection")
    Set rs = CreateObject("ADODB.Recordset")
    With cn
    .Provider = "Microsoft.Jet.OLEDB.4.0"
    .Properties("Extended Properties") = "Excel 8.0;HDR=No;"
    .Open ThisWorkbook.FullName
    End With


    Thank you can we simplify ?
    Try my code is so simple

  6. #6
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,516

    Re: VBA copy and paste with criteria and different sheets

    Quote Originally Posted by sokour View Post
    Thank you can we simplify ?
    That is to enable Active Data Object to connect to a data and it's a fixed string depends on the version of Excel.

    Perhaps the link below will help.

    https://analysistabs.com/excel-vba/a...ting-database/

    This would be easier to understand.
    Again, you will need to review your formula in bold.
    Please Login or Register  to view this content.
    Last edited by jindon; 11-07-2018 at 10:58 PM.

  7. #7
    Registered User
    Join Date
    11-02-2018
    Location
    London
    MS-Off Ver
    2007
    Posts
    6

    Re: VBA copy and paste with criteria and different sheets

    I try your code but it didnt take in consideration from what I need : "So first in "Source Data", I only select the lines or appear "103" in column A:"

    thank you can you help to add this criteria ?

  8. #8
    Registered User
    Join Date
    11-02-2018
    Location
    London
    MS-Off Ver
    2007
    Posts
    6

    Re: VBA copy and paste with criteria and different sheets

    Quote Originally Posted by daboho View Post
    Try my code is so simple
    I try your code but it didnt take in consideration from what I need : "So first in "Source Data", I only select the lines or appear "103" in column A:"

    thank you can you help to add this criteria ?

  9. #9
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,516

    Re: VBA copy and paste with criteria and different sheets

    I don't understand what you are talking about.
    Attached Files Attached Files

  10. #10
    Registered User
    Join Date
    11-02-2018
    Location
    London
    MS-Off Ver
    2007
    Posts
    6

    Re: VBA copy and paste with criteria and different sheets

    Sorry jindon, I mean for the code of daboho : the code didnt take in account the criteria we select the line with 103 on the column A

    Thank you

  11. #11
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,516

    Re: VBA copy and paste with criteria and different sheets

    OK, understood.

  12. #12
    Registered User
    Join Date
    11-02-2018
    Location
    London
    MS-Off Ver
    2007
    Posts
    6

    Re: VBA copy and paste with criteria and different sheets

    Quote Originally Posted by jindon View Post
    OK, understood.
    But I would like to thank for the time you help< Iwill try your last code.
    But as A begginer I want to learn as well do you think its ok if you can add the commentary on the code ?

    Thank you!

  13. #13
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,516

    Re: VBA copy and paste with criteria and different sheets

    The last code is written very simple using AutoFilter.

    If you want to understand the code, step debug for yourself first.

    While you are in VBE:

    Shrink the window to see your worksheet behind VBE.
    Click somewhere on the code and hit F8.

    As you hit F8, code execute one line and you will see the action on the worksheet at the same time.

    And if you still have problem, ask the line(s) that you don't understand.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. [SOLVED] VBA Copy and Paste on criteria match through multiple sheets
    By ExcelKing424 in forum Excel Programming / VBA / Macros
    Replies: 12
    Last Post: 03-06-2018, 06:44 AM
  2. Copy/Paste from mastersheet to individual sheets based on criteria
    By tnsvolley in forum Excel Programming / VBA / Macros
    Replies: 10
    Last Post: 04-23-2015, 08:23 AM
  3. [SOLVED] Macro to copy and paste based on criteria to 11 separate sheets
    By msmith7113 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 04-11-2013, 02:30 AM
  4. Replies: 0
    Last Post: 11-27-2012, 10:32 AM
  5. Copy and paste data to separate sheets based on mutiple criteria again
    By Ricker090 in forum Excel Programming / VBA / Macros
    Replies: 12
    Last Post: 07-13-2011, 02:23 PM
  6. Copy and paste data to separate sheets based on mutiple criteria
    By Ricker090 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 04-21-2011, 03:48 PM
  7. MS Excel 2003 macro to copy paste data in different sheets based on certain criteria
    By bhaktprahlad in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 09-02-2010, 06:17 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1