Detect If New Row of Data is Added

  • Hi all,


    I have yet another burning question regarding macros this time. I am trying to build a macro which detects a new row of data added, which are data drawn from a web query.


    This web query draws rows of data based on countries, and there might be new countries each time it is refreshed in the workbook. I would like to use my copy and paste macro to paste country data into another sheet in the same workbook. However, my copy paste macro only pastes data based on the top row countries (eg A1 = Argentina), but does not detect if there are new country data drawn from the web query.


    Is there anyone that knows how to build a macro which detects the new country row?


    Also, I would like the macro to show a notification to tell the user that there is a new country found (e.g. Country A is new, please insert a new column).


    Thanks!


    ~ Hestia

  • Hello,


    A generic answer ... to a very generic question ...


    For your macro to detect if a new row of data has been added :


    You need to work out the difference between two counts ...


    On one hand, the number of rows of your previous download, and,


    on the other hand, the number of rows of your current download


    HTH

    If you feel like saying "Thank You" for the help received, do not hesitate to click the "Smiley" icon, below, in the bottom right corner :)

  • Hi Carim,


    Thanks for the answer above. I will try making a macro following these comments.


    If i have any problems regarding it, will post it here


    ~ Hestia

  • Hi all,


    Here is the file that I am working on currently.


    I would like to actually copy data from cells J18 to O73 and copy them according to the months on J14:O14 and also based on countries on column B in "Data Draw sheet". Then I would like to paste them accordingly into the "Working Sheet" (eg: Apr-18 Argentina on cell C221). I have already done a macro to copy and paste the values i needed.


    However i am not sure how to detect if there are any new countries added in column B, then show a notice of the countries that are new.


    Is there anyone that could help me with this?


    ~ Hestia

  • Hello,


    After your Web query ... you could run following macro ...



    Hope this will help

    If you feel like saying "Thank You" for the help received, do not hesitate to click the "Smiley" icon, below, in the bottom right corner :)

  • Hi Carim,


    Yes I tweaked the codes to my settings and now it works perfectly!


    Here is how it looks now:



    However, I would also like to include a code which detects which is the new column of data and paste the data accordingly to the dates. Is it alright if you could help me with this too please?


    Thanks for your help again!


    ~ Hestia

  • I think my explanation is not that clear, hence here is a more detailed explanation regarding my question.


    I have 6 rows of data drawn from a web query, and pasted into the "working sheet". These 6 rows include dates in the format of (mmm-yyyy) in column A, different countries in each column and values belonging to the different countries.


    In the "copy paste sheet", i have historical data which follows the same format as the working sheet.


    What I would like to do is:


    If any of the dates for the six rows of data in "working sheet" = any of the dates in "copy paste sheet", then copy all of the row's data (starting from column B) from "working sheet" and paste it onto the row with matching dates in "copy paste sheet". It is like a vlookup but using vba, and i am not sure how to code it as well.


    However, there might be new countries in the columns of working sheet. Besides showing the number of new countries, I would like the macro to show which are the new countries.


    Hopefully this is a clearer explanation.


    ~ Hestia

  • Hi all,


    I tried following a video online using this code:



    However, this only copies and pastes the row of data in the exact cell destination on the next sheet.


    Is there anyone that could help me with this please?


    Thanks

  • Hi all,


    Sorry I got it solved. Turns out that I was using a cursive " " for the lower half of my codes, so half of my codes did not register and copy pasted the data based on cell destination rather than finding the correct reference.



    Here is the code if anyone needs it.


    Have a nice day! (p.s. will stop spamming this thread alr haha)


    ~ Hestia

  • Hi,


    For all the future readers of the Forum ...


    Thanks for sharing your solution ...:smile:

    If you feel like saying "Thank You" for the help received, do not hesitate to click the "Smiley" icon, below, in the bottom right corner :)

Participate now!

Don’t have an account yet? Register yourself now and be a part of our community!