+ Reply to Thread
Results 1 to 6 of 6

creating a loop in a macro

Hybrid View

  1. #1
    Registered User
    Join Date
    04-05-2013
    Location
    new york, new york
    MS-Off Ver
    Excel 2010
    Posts
    19

    creating a loop in a macro

    Hi,

    I need help creating a macro that loops the calculations. Currently I have a drop down list in a sheet and I have a macro that picks each individual name calculates the results and then copies and pastes the 2 cells that I need in to a table. This repeats itself dozens of times. I need help that the macro should automatically choose the next name in the table, paste it in the drop down menu, calculate, and paste results in the table, and of course repeat. I’m attaching part of the macro, if anybody can take a look it would be really appreciated.
    Attached Files Attached Files
    Last edited by moshro1; 09-17-2014 at 01:05 PM.

  2. #2
    Forum Expert
    Join Date
    10-09-2012
    Location
    Dallas, Texas
    MS-Off Ver
    MO 2010 & 2013
    Posts
    3,049

    Re: creating a loop in a macro

    Can you post the code to the forum as well (for those of us on our phones hah)?
    Please ensure you mark your thread as Solved once it is. Click here to see how.
    If a post helps, please don't forget to add to our reputation by clicking the star icon in the bottom left-hand corner of a post.

  3. #3
    Forum Guru HaHoBe's Avatar
    Join Date
    02-19-2005
    Location
    Hamburg, Germany
    MS-Off Ver
    work: 2016 on Win10 (notebook), private: 365 on Win11 (desktop), 2019 on Win11 (notebook)
    Posts
    8,199

    Re: creating a loop in a macro

    Hi, moshro1,

    maybe like this:
    Sub summarize_Stock()
    ' summarize_Stock Macro
    Dim arNames As Variant
    Dim lngCtr As Long
    
    arNames = Array("AAPL", "AMZN")
    
    For lngCtr = LBound(arNames) To UBound(arNames)
      Sheets("Stock_Price").Range("A2").Value() = arNames(lngCtr)
      Calculate
      Sheets("Summary").Cells(2 + lngCtr, "B").Resize(1, 2).Value = Sheets("Stock_Price").Range("L41:M41").Value
    Next lngCtr
    End Sub
    Although you would be better of if you had attached a sample workbook.

    Ciao,
    Holger
    Use Code-Tags for showing your code: [code] Your Code here [/code]
    Please mark your question Solved if there has been offered a solution that works fine for you

  4. #4
    Registered User
    Join Date
    04-05-2013
    Location
    new york, new york
    MS-Off Ver
    Excel 2010
    Posts
    19

    Re: creating a loop in a macro

    Thank you Holger. I did some tweaking and it worked perfectly! I only wish that I can get some kind of copy paste for the array formula instead of typing in each cell separately in to the array.

  5. #5
    Forum Guru HaHoBe's Avatar
    Join Date
    02-19-2005
    Location
    Hamburg, Germany
    MS-Off Ver
    work: 2016 on Win10 (notebook), private: 365 on Win11 (desktop), 2019 on Win11 (notebook)
    Posts
    8,199

    Re: creating a loop in a macro

    Hi, moshro1,

    if there is a range where the names are located this may be referenced instead of using an array - like I said: no information in the word document available.

    Ciao,
    Holger

  6. #6
    Registered User
    Join Date
    04-05-2013
    Location
    new york, new york
    MS-Off Ver
    Excel 2010
    Posts
    19

    Re: creating a loop in a macro

    yup they were in column A from A2:A51...

+ 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] Creating a macro -using for loop
    By Meeraan in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 09-14-2014, 02:00 AM
  2. Creating a Loop for Macro
    By glide2131 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 06-19-2014, 08:02 PM
  3. creating a loop in a macro
    By bobfoley91 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 03-20-2014, 08:33 AM
  4. [SOLVED] Need help creating a loop in a macro!!!!
    By moshro1 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 06-14-2013, 01:46 PM
  5. Creating a Macro / GUI that is continuous and does not loop
    By C Dev in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 07-26-2012, 04:45 AM

Tags for this Thread

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