+ Reply to Thread
Results 1 to 24 of 24

Simple macro repetition, I am a total noob

  1. #1
    Registered User
    Join Date
    10-09-2014
    Location
    Illinois
    MS-Off Ver
    2003
    Posts
    17

    Simple macro repetition, I am a total noob

    I have a list of stock prices in excel that looks like this

    stock prices needed 10/7/2014
    UYM 50.85 51.42 49.88 49.93 6410.93
    V 210.81 211.09 207.85 208.05 22375.57
    VAC 61.52 61.75 60.48 60.58 1001.44
    VAL 77.45 77.68 76.73 76.81 4599.69
    VALE 11.34 11.58 11.29 11.39 362664.57
    VAR 80.69 82.74 80.69 80.82 31238.55


    they are the october 7 2014 open hi low and close and volume for the symbols in column a
    the list is much longer than I've pasted

    I need to copy the data for each stock and paste it into that stocks price file in the row for that particular date. the price file looks like this
    10/03/2014 UYM 51.980 52.190 51.460 51.620 139
    10/06/2014 UYM 51.820 52.120 51.400 51.600 185
    10/07/2014 UYM 0 0 0 0 0
    10/08/2014 UYM 49.66 51.04 48.52 51.01 277


    i recorded a little macro which will performs the task for UYM. how to I tweak it so it will go down the list of stocks and copy and save the data for each one until I complete the entire list.

    here is what I have so far
    Please Login or Register  to view this content.
    thank you!
    Last edited by Leith Ross; 10-09-2014 at 01:50 PM. Reason: Added Code Tags

  2. #2
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,258

    Re: Simple macro repetition, I am a total noob

    Hello chart23,

    Welcome to the Forum!

    If you have a workbook you can post, it would help.

    Please provide before and after examples of your data along with any notes you would like to include.

    If your workbook contains any sensitive information, please redact that information before you post.

    How To Post Your Workbook
    1. At the bottom right of the Reply window, Click the button Go Advanced
    2. At the top of the Your Message Window, in the first row of icons, Click the Paperclip icon.
    3. Click the Add Files button at the top right in the dialog box. This displays the File Manager dialog.
    4. Click the Select Files button at the bottom middle of the dialog.
    5. In the new window Find the file you want to upload, select it, and Click Open.
    6. You will now be back in the File Manager dialog. Click the bottom Middle button Upload File.
    7. Wait until the file has completely uploaded before you exit the File Manager dialog.
    Sincerely,
    Leith Ross

    Remember To Do the Following....

    1. Use code tags. Place [CODE] before the first line of code and [/CODE] after the last line of code.
    2. Thank those who have helped you by clicking the Star below the post.
    3. Please mark your post [SOLVED] if it has been answered satisfactorily.


    Old Scottish Proverb...
    Luathaid gu deanamh maille! (Rushing causes delays!)

  3. #3
    Forum Expert daffodil11's Avatar
    Join Date
    07-11-2013
    Location
    Phoenixville, PA
    MS-Off Ver
    MS Office 2016
    Posts
    4,465

    Re: Simple macro repetition, I am a total noob

    What are you calling the source workbook? Does the source workbook have a sheet name? Does the destination? How should this macro reference the date?
    Make Mom proud: Add to my reputation if I helped out!

    Make the Moderators happy: Mark the Thread as Solved if your question was answered!

  4. #4
    Registered User
    Join Date
    10-09-2014
    Location
    Illinois
    MS-Off Ver
    2003
    Posts
    17

    Re: Simple macro repetition, I am a total noob

    i am trying to attach the workbook but it is 3mb so too big.

    not sure why a excel spread sheet with 6 columns of data and 105 rows is that big. probably i am doing something wrong?

  5. #5
    Registered User
    Join Date
    10-09-2014
    Location
    Illinois
    MS-Off Ver
    2003
    Posts
    17

    Re: Simple macro repetition, I am a total noob

    the source workbook is an excel worksheet called "fix prices"
    the sheetname (i am assuming this means the tab on the bottom) is "datsheet file"
    the destination files are the stock symbol .xls (for example uvm.xls) with sheetname of templ

    the date I input into the fix prices datsheet file sheet in cell C1. it remains the same

  6. #6
    Registered User
    Join Date
    10-09-2014
    Location
    Illinois
    MS-Off Ver
    2003
    Posts
    17

    Re: Simple macro repetition, I am a total noob

    well i figured out why my file was so big. so at least i've solved one excel problem today (i think). attached is the workbook
    Attached Files Attached Files

  7. #7
    Forum Expert daffodil11's Avatar
    Join Date
    07-11-2013
    Location
    Phoenixville, PA
    MS-Off Ver
    MS Office 2016
    Posts
    4,465

    Re: Simple macro repetition, I am a total noob

    Maybe something like this? Be sure to have a file backups located in another place. Macros that cycle through files multiple files can't be undone.

    Please Login or Register  to view this content.

  8. #8
    Registered User
    Join Date
    10-09-2014
    Location
    Illinois
    MS-Off Ver
    2003
    Posts
    17

    Re: Simple macro repetition, I am a total noob

    thank you very much for taking the time to write that. I tried running it and it runs without error and closes at the end. however the data isnt copied. i tried stepping through using f8 and there were no errors but I didnt see anything happen until it closes and again the data has not been copied. am I doing something wrong?

  9. #9
    Registered User
    Join Date
    10-09-2014
    Location
    Illinois
    MS-Off Ver
    2003
    Posts
    17

    Re: Simple macro repetition, I am a total noob

    I took out the "On Error Resume Next"
    and stepped through it is highlighting this line
    Set StockDate = wb.ws.Range("C1") and giving me an error which says "run-time error "438': object doesnt support this property or method"

  10. #10
    Forum Expert daffodil11's Avatar
    Join Date
    07-11-2013
    Location
    Phoenixville, PA
    MS-Off Ver
    MS Office 2016
    Posts
    4,465

    Re: Simple macro repetition, I am a total noob

    Could try spelling it out instead.

    Please Login or Register  to view this content.

  11. #11
    Registered User
    Join Date
    10-09-2014
    Location
    Illinois
    MS-Off Ver
    2003
    Posts
    17

    Re: Simple macro repetition, I am a total noob

    it got hung up on
    For Each c In wb.ws.Range("A1:A1000")

    so i tried spelling it out, (I think) as
    For Each c In Workbooks("fix prices.xls").Sheets("datsheet file")("A2:A1000")
    but it still got hung up, with the same runtime error 438

  12. #12
    Forum Expert daffodil11's Avatar
    Join Date
    07-11-2013
    Location
    Phoenixville, PA
    MS-Off Ver
    MS Office 2016
    Posts
    4,465

    Re: Simple macro repetition, I am a total noob

    You'll need to try adjusting both references.

    Set StockDate = Workbooks("fix prices.xls").Sheets("datsheet file").Range("C1")

    For Each c In Workbooks("fix prices.xls").Sheets("datsheet file").Range("A1:A1000")

  13. #13
    Registered User
    Join Date
    10-09-2014
    Location
    Illinois
    MS-Off Ver
    2003
    Posts
    17

    Re: Simple macro repetition, I am a total noob

    ok. i see where I screwed up that part by leaving out ".Range" in the spelled out version. it now is fixed.

    however it steps a few lines down and i get a runtime error 1004 'C:Analysis\.xls" could not be found check the spelling of the file name and verify that the file location is correct

    highlighted the line: Workbooks.Open Filename:="C:\Analysis\" & c & ".xls"

    thanks again for sticking with me through me incompentence

  14. #14
    Registered User
    Join Date
    10-09-2014
    Location
    Illinois
    MS-Off Ver
    2003
    Posts
    17

    Re: Simple macro repetition, I am a total noob

    not sure if this is relevant. but i noticed when it steps through the line If c <> "" Then Range(c.Offset(0, 1), c.Offset(0, 5)).Copy
    it only highlights If c <> "" Then

  15. #15
    Registered User
    Join Date
    10-09-2014
    Location
    Illinois
    MS-Off Ver
    2003
    Posts
    17

    Re: Simple macro repetition, I am a total noob

    ok. it looks like that hangup was because the datsheetfile had a blank cell in a1. so i moved the stock date from c1 to g1 and shifted all the stocks and prices up. changed the set stockdate line so that it looked at g1 for the date.

    I now can step to the point where it copys the data on datsheet and opens the correct stocks c:analysis file

    but then i get an error at RowX = WorksheetFunction.Match(StockDate, "[" & c & "]Sheet1!A2:A999", 0)
    which says "runtime error 1004 unable to get the match property of the worksheetfunction class"

  16. #16
    Registered User
    Join Date
    10-09-2014
    Location
    Illinois
    MS-Off Ver
    2003
    Posts
    17

    Re: Simple macro repetition, I am a total noob

    I'm going to try and spell out the StockDate in that line
    replace StockDate with Workbooks("fix prices.xls").Sheets("datsheet file").Range("G1")

    which will look like
    RowX = WorksheetFunction.Match(Workbooks("fix prices.xls").Sheets("datsheet file").Range("G1"), "[" & c & "]Sheet1!A2:A999", 0)

  17. #17
    Registered User
    Join Date
    10-09-2014
    Location
    Illinois
    MS-Off Ver
    2003
    Posts
    17

    Re: Simple macro repetition, I am a total noob

    that didnt work either. not sure why it is having such a hard time finding the date in the analysis file

  18. #18
    Forum Expert daffodil11's Avatar
    Join Date
    07-11-2013
    Location
    Phoenixville, PA
    MS-Off Ver
    MS Office 2016
    Posts
    4,465

    Re: Simple macro repetition, I am a total noob

    One issue it will have, is when no match exists.

    When you type a formula into a cell and the formula doesn't work, you just get an error message.

    When a formula doesn't work in VB, the VB crashes.

  19. #19
    Registered User
    Join Date
    10-09-2014
    Location
    Illinois
    MS-Off Ver
    2003
    Posts
    17

    Re: Simple macro repetition, I am a total noob

    the match is def there unless I am referencing the wrong cell

    could I check if this is the issue by replacing StockDate with say DD and inputing DD into the analysis file column for it to look for?

    say RowX = WorksheetFunction.Match("DD", "[" & c & ".xls] Sheet1!A2:A999", 0)
    ?

  20. #20
    Forum Expert daffodil11's Avatar
    Join Date
    07-11-2013
    Location
    Phoenixville, PA
    MS-Off Ver
    MS Office 2016
    Posts
    4,465

    Re: Simple macro repetition, I am a total noob

    I sat and stared at the screen for a while until this made sense. I had a number of errors in the code.

    I created an Analysis folder in C and then also created a UYM file and was able to get this to work. The biggest hangup was being caused by improper syntax of the MATCH function. In VB land, reference to sheets, cells, and filenames have to conform to object types. So instead of saying [uym.xls]Sheet1!blahblah I had to spell out Workbook(c & ".xls").Sheets("Sheet1").Range(blahblah)

    The actual sheet name for your UYM file may differ.

    Please Login or Register  to view this content.

  21. #21
    Registered User
    Join Date
    10-09-2014
    Location
    Illinois
    MS-Off Ver
    2003
    Posts
    17

    Re: Simple macro repetition, I am a total noob

    Sweet. you are a brilliant flower Daffodil! if it's kosher pm me info and I will P pal u an andrew jackson.

    was part of the issue you didnt declare RowX as an integer?

  22. #22
    Forum Expert daffodil11's Avatar
    Join Date
    07-11-2013
    Location
    Phoenixville, PA
    MS-Off Ver
    MS Office 2016
    Posts
    4,465

    Re: Simple macro repetition, I am a total noob

    It might have been.

    Defining the dimensions of each variable isn't always necessary (depending on how it's used), but since the code was being a pain I was just being thorough when I went back.

  23. #23
    Registered User
    Join Date
    10-09-2014
    Location
    Illinois
    MS-Off Ver
    2003
    Posts
    17

    Re: Simple macro repetition, I am a total noob

    Well, thank you very much. this simple little macro is going to save me a lot of time, and hopefully help me come up with similar fixes in the future. I truly appreciate your help.

  24. #24
    Forum Expert daffodil11's Avatar
    Join Date
    07-11-2013
    Location
    Phoenixville, PA
    MS-Off Ver
    MS Office 2016
    Posts
    4,465

    Re: Simple macro repetition, I am a total noob

    No problem. I enjoy a good riddle, moreso when I can solve it.

    Don't forget to mark the thread as solved, under Thread Options at the top.

+ 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] Total Noob needs help - I think with formatting.
    By mdtiberio in forum Excel - New Users/Basics
    Replies: 3
    Last Post: 12-16-2013, 01:38 PM
  2. Complete and total Noob!
    By bdavis711 in forum Hello..Introduce yourself
    Replies: 1
    Last Post: 09-07-2012, 04:27 PM
  3. Total NOOB LOOP
    By nabsibouch in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 02-16-2009, 10:12 PM
  4. HELP for a total noob
    By Dagz in forum Excel - New Users/Basics
    Replies: 4
    Last Post: 03-24-2008, 01:03 AM
  5. [SOLVED] I need a simple macro but im a noob.
    By flyboy0204 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 01-21-2006, 12:25 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