+ Reply to Thread
Results 1 to 13 of 13

VBA Simple Check if 2 cells matches and if that is true it will copy and paste data .

  1. #1
    Registered User
    Join Date
    12-22-2014
    Location
    Netherlands
    MS-Off Ver
    O365
    Posts
    58

    VBA Simple Check if 2 cells matches and if that is true it will copy and paste data .

    Hi There,

    This must be very simple to make.
    but i sadly lack the knowledge to produce this.

    Here is my Story.

    I need VBA to tell if A1 and A2 Equals (This is a date) than i need him to check in tab History if that date matches the date inside the cell than i need him to copy and paste the value of DATA C4 to C6 to corresponding date Column

    But this can only occure after the button is pressed.

    I have in A1 a today formula
    I have VBA inputting Range("A2").Value = Date (this happens when i press the get data button this button will load data from different sources we need to do this on a daily basis)


    The column data is where the data needs to be extracted and History is where the data must go.
    This way we can see what the value does on a daily basis.

    I hope this is understandable.

    greetings !
    Attached Files Attached Files

  2. #2
    Forum Moderator - RIP Richard Buttrey's Avatar
    Join Date
    01-14-2008
    Location
    Stockton Heath, Cheshire, UK
    MS-Off Ver
    Office 365, Excel for Windows 2010 & Excel for Mac
    Posts
    29,464

    Re: VBA Simple Check if 2 cells matches and if that is true it will copy and paste data .

    Hi

    It's not clear to me what you're asking.

    First of all we need to see the workbook you're trying to load. Please upload it.

    Are you saying that the file you load looks like the data in B3:B7 on the Data sheet and that this will have a date somewhere and that date should be placed in A2?

    Then finally the data you've loaded should be added to the appropriate column of the History sheet.
    And if so which cells. C4:C6 or D4:D6 or something else?


    As an aside your line of code
    Formula: copy to clipboard
    Please Login or Register  to view this content.
    needs to be inside a procedure. i.e. a
    Please Login or Register  to view this content.
    I'd also consider turning the history sheet through 90 degrees so that the dates are down column A and the values down columns B:D. This is a more 'natural' way of keeping a database and will simplify any future analysis you may require.
    Richard Buttrey

    RIP - d. 06/10/2022

    If any of the responses have helped then please consider rating them by clicking the small star icon below the post.

  3. #3
    Forum Guru Kaper's Avatar
    Join Date
    12-14-2013
    Location
    Warsaw, Poland
    MS-Off Ver
    most often: Office 365 in Windows environment
    Posts
    8,613

    Re: VBA Simple Check if 2 cells matches and if that is true it will copy and paste data .

    If I understood well, ou may try such code:

    Please Login or Register  to view this content.
    Attached Files Attached Files
    Best Regards,

    Kaper

  4. #4
    Registered User
    Join Date
    12-22-2014
    Location
    Netherlands
    MS-Off Ver
    O365
    Posts
    58

    Re: VBA Simple Check if 2 cells matches and if that is true it will copy and paste data .

    Hi Richard,

    Thanks for responding.

    I can't upload the actual workbook it has sensitive information. It contains all the information of our Warehouses

    The Information on B3:B7 is the actual information that needs to be copied to the date range.
    the data that is being copied should be added on the Column that contains the same date. (sheet history)

    so after pressing the refresh macro (lotsa loading and copy paste etc) than at the final stage of the macro i have inputted Range("A2").value = date.
    I did this because i needed to validate if the excel formula (=today() equals the date that just has been printed by the button with conditional formatting.

    So here i'll explain my question again.

    I need VBA upon pressing my button (which allready exists)

    to do the following. (this ofcourse after printing my date which allready exists)

    Check if A1 matches A2 if so:
    Copy data from C4 to C6
    Paste it to the corresponding (date of today. because that's what both a1 and a2 do) column in worksheet History.

    and that's it

    hope its more clear now !

  5. #5
    Registered User
    Join Date
    12-22-2014
    Location
    Netherlands
    MS-Off Ver
    O365
    Posts
    58

    Re: VBA Simple Check if 2 cells matches and if that is true it will copy and paste data .

    Hey Man,

    This is exactly what i was looking for !
    thanks for your time !

    im trying to learn vba every now and than.
    but also actually busy with understanding Excel itself

    ty sir!

  6. #6
    Registered User
    Join Date
    12-22-2014
    Location
    Netherlands
    MS-Off Ver
    O365
    Posts
    58

    Re: VBA Simple Check if 2 cells matches and if that is true it will copy and paste data .

    oof, almost there.

    my c4:c6 isn't on the worksheet DATA but on one called Pivot.
    the range If .Range("A2") = .Range("A3") Then / is on the worksheet DATA
    (so i have 3 different ranges.)

    :S

  7. #7
    Registered User
    Join Date
    12-22-2014
    Location
    Netherlands
    MS-Off Ver
    O365
    Posts
    58

    Re: VBA Simple Check if 2 cells matches and if that is true it will copy and paste data .

    in suplement of my previous post i tried to bake this:

    sadly it's not working yet

    the yellow part is where it stops.

    Please Login or Register  to view this content.
    Last edited by Desotronics; 05-10-2019 at 02:20 PM.

  8. #8
    Forum Moderator - RIP Richard Buttrey's Avatar
    Join Date
    01-14-2008
    Location
    Stockton Heath, Cheshire, UK
    MS-Off Ver
    Office 365, Excel for Windows 2010 & Excel for Mac
    Posts
    29,464

    Re: VBA Simple Check if 2 cells matches and if that is true it will copy and paste data .

    Quote Originally Posted by Desotronics View Post
    Hi Richard,

    Thanks for responding.

    I can't upload the actual workbook it has sensitive information. It contains all the information of our Warehouses


    So here i'll explain my question again.

    I need VBA upon pressing my button (which allready exists)

    Just desensitise the data. We don't need to know the real names or contents of your warehouses. Neither do we need every single row of data, just a sufficiently representative example.

    And neither did I see any button.

  9. #9
    Registered User
    Join Date
    12-22-2014
    Location
    Netherlands
    MS-Off Ver
    O365
    Posts
    58

    Re: VBA Simple Check if 2 cells matches and if that is true it will copy and paste data .

    Hey man,

    thanks for responding.

    The dashboard that we got is way to big to clear out of information everything points to one another.

    the setup that i uploaded is the same exact thing as what i work with without all the data. now updated with a button !

    greetings

    aaron

  10. #10
    Forum Moderator - RIP Richard Buttrey's Avatar
    Join Date
    01-14-2008
    Location
    Stockton Heath, Cheshire, UK
    MS-Off Ver
    Office 365, Excel for Windows 2010 & Excel for Mac
    Posts
    29,464

    Re: VBA Simple Check if 2 cells matches and if that is true it will copy and paste data .

    Here's the code I'd use for the button

    Please Login or Register  to view this content.

  11. #11
    Registered User
    Join Date
    12-22-2014
    Location
    Netherlands
    MS-Off Ver
    O365
    Posts
    58
    Quote Originally Posted by Richard Buttrey View Post
    Here's the code I'd use for the button

    Please Login or Register  to view this content.
    Thanks man I will try this at work tomorrow

    Greetings

    Aaron

  12. #12
    Registered User
    Join Date
    12-22-2014
    Location
    Netherlands
    MS-Off Ver
    O365
    Posts
    58

    Re: VBA Simple Check if 2 cells matches and if that is true it will copy and paste data .

    Hey richard,

    i used the piece of code of Kaper.

    and now it works

    Please Login or Register  to view this content.
    thanks for your help.
    Last edited by Desotronics; 05-10-2019 at 02:19 PM.

  13. #13
    Forum Guru Kaper's Avatar
    Join Date
    12-14-2013
    Location
    Warsaw, Poland
    MS-Off Ver
    most often: Office 365 in Windows environment
    Posts
    8,613

    Re: VBA Simple Check if 2 cells matches and if that is true it will copy and paste data .

    Glad to hear it works, but please observe forum rules (there are just few):

    Rule 2 says, that you need to include code tags around your code.

    Please take a moment to add the tags to above post and previous one: https://www.excelforum.com/excel-pro...ml#post5117573

    Posting code between [CODE]Please [url=https://www.excelforum.com/login.php]Login or Register [/url] to view this content.[/CODE] tags makes your code much easier to read and copy for testing, and it also maintains VBA formatting.

    Click on Edit to open your post, then highlight your code and click the # icon at the top of your post window. More information about these and other tags can be found here

    (Note: this change is not optional. No further responses shall be posted until this request has been fulfilled.)

+ 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] Populate cells with data from other cells if 2 matches are true
    By vayana in forum Excel General
    Replies: 4
    Last Post: 07-12-2015, 11:53 AM
  2. [SOLVED] Check values seperated by comma, if matches copy cells
    By dervish65 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 06-13-2013, 04:40 PM
  3. Macro for WS/WB comparisons, and copy/paste two cells based on matches
    By adilley in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 10-13-2011, 10:46 PM
  4. Check if two cells are equal and copy,paste cell if true
    By solomeros in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 07-29-2011, 01:22 AM
  5. Macro to Copy and Paste cells if TRUE
    By Ugene in forum Excel Programming / VBA / Macros
    Replies: 10
    Last Post: 12-04-2009, 05:32 PM
  6. copy data of check box is clicked true
    By pichai in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 01-20-2008, 02:13 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