+ Reply to Thread
Results 1 to 6 of 6

Macro to add new entry to growing list pls

  1. #1
    Registered User
    Join Date
    03-23-2011
    Location
    London, England
    MS-Off Ver
    Excel 2000
    Posts
    4

    Macro to add new entry to growing list pls

    Hello I want to add items to an existing list on a single worksheet. The item line(s) are from an external source which I put into a box at the top of the worksheet.

    I record a keystroke macro, which works, but on next using the macro, it has "range-valued" the original last item, so instead of adding a new entry to the list, the macro replaces the last one entered via the macro.

    Currently, I copy (Ctrl-C) the item "box", then:

    Ctrl-end, Ctrl-left, down (arrow) - so to arrive on the last item, then down one line - then Ctrl-V the "box" into this "next empty cell".

    Hey presto -except, as mentioned, the macro sets the "next empty cell" in concrete so just overwrites any previous entry arriving via the macro.

    Help please?

    PS I'm not up on Vis Basic. By "range valued", in DOS it'd be like using $ to fix the "next empty cell" which I don't want the macro to do, given it's supposed to be finding the latest entry, not the last one when I originally recorded the macro.

  2. #2
    Forum Expert Domski's Avatar
    Join Date
    12-14-2009
    Location
    A galaxy far, far away
    MS-Off Ver
    Darth Office 2010
    Posts
    3,950

    Re: Macro to add new entry to growing list pls

    This will add the value from C1 to the end of a list in column A:

    Please Login or Register  to view this content.

    Dom
    "May the fleas of a thousand camels infest the crotch of the person who screws up your day and may their arms be too short to scratch..."

    Use code tags when posting your VBA code: [code] Your code here [/code]

    Remember, saying thanks only takes a second or two. Click the little star to give some Rep if you think an answer deserves it.

  3. #3
    Registered User
    Join Date
    03-23-2011
    Location
    London, England
    MS-Off Ver
    Excel 2000
    Posts
    4

    Re: Macro to add new entry to growing list pls

    Many thanks and more again for replying so quickly

    I'm trying to figure out how to record that... Do I do a keystroke record, then step into to change it?

    I can't find a tools/macro option that allows me to write one from scratch. Sorry if numpty.

    Many thanks

  4. #4
    Forum Expert Domski's Avatar
    Join Date
    12-14-2009
    Location
    A galaxy far, far away
    MS-Off Ver
    Darth Office 2010
    Posts
    3,950

    Re: Macro to add new entry to growing list pls

    It's not recorded code. The macro recorder would never come up with anything like that.

    You would need to add a regular code module to your workbook's VBA project and then add the code to it.

    Details can be found here: http://www.contextures.com/xlvba01.html

    The full code would need to be more like this:

    Please Login or Register  to view this content.

    Dom

  5. #5
    Registered User
    Join Date
    03-23-2011
    Location
    London, England
    MS-Off Ver
    Excel 2000
    Posts
    4

    Re: Macro to add new entry to growing list pls

    Dom, I'll study the link and see what's what as it could be the answer to a few problems given it is irritating when keystroke macros don't perform as expected.

    In my Lotus 123 days, their macros also had code that wasn't keystrokes and similarly one just had to learn it, so I feel a book purchase (or borrow from library) coming on also...

    Thanks for the insight

  6. #6
    Forum Contributor
    Join Date
    07-22-2009
    Location
    Minneapolis, MN
    MS-Off Ver
    2016
    Posts
    220

    Re: Macro to add new entry to growing list pls

    Quote Originally Posted by Domski View Post
    It's not recorded code. The macro recorder would never come up with anything like that.

    You would need to add a regular code module to your workbook's VBA project and then add the code to it.

    Details can be found here: http://www.contextures.com/xlvba01.html

    The full code would need to be more like this:

    Please Login or Register  to view this content.

    Dom
    I ran a test, and this line of code works great! However, let's say that I wanted "Range("A" & Rows.Count).End(xlUp).Offset(1, 0)" to be located on a different workbook...

    Open desired workbook, add Range("C1").Value to the desired workbook, save & close desired workbook.

    Here is a sample of what I'm looking to do, but am not sure how to change it to work properly.

    Can anyone help?


    Please Login or Register  to view this content.
    EDIT:
    I figured out how to make it work, but I'm curious if/ how I could condense it down.

    Please Login or Register  to view this content.
    Last edited by Rerock; 04-22-2013 at 12:33 PM.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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