VBA loop help

Discussion in 'App Development' started by minmike, Apr 12, 2014.

  1. minmike

    minmike

    Sorry if this is basic, but I'm looking to set up a loop.

    I have a spread sheet and I want to test a range of variables and save the results. I'm good with excel, but learning VBA.

    So the loop would start at value 0, copy results and value. Change value +1. record new result and new value 1 cell below previous. Repeat until end value reached.

    Any help would be greatly appreciated.
     
  2. minmike

    minmike

    Thanks. It tried some of the free tutorials, but I still need a bit more help.

    Which language should I focus on at codeacadamy? I think python is the closest, but I didn't see a vb/vba course?

    I think the Data table function gets approximately what I am looking for. Not perfect but a reasonable work around.
     
  3. I'm having trouble figuring out exactly what you want to do, but below is a loop that will look at the value in column A, multiply it by 2, and put the result in column B. It will do this for the first 10 rows of the active sheet.

    For i = 1 To 10
    ActiveWorkbook.ActiveSheet.Cells(i, 2).Value = ActiveWorkbook.ActiveSheet.Cells(i, 1).Value * 2
    Next i


    This type of loop is called a "For-Next loop" and you can find a lot of examples online.