+ Reply to Thread
Results 1 to 9 of 9

Loops with numbers and text

  1. #1
    Registered User
    Join Date
    01-29-2010
    Location
    Scotland
    MS-Off Ver
    Excel 2010
    Posts
    94

    Loops with numbers and text

    Hi All,

    I am new to this and trying to understand loops and arrays

    I have my first loop that adds 1 to 10 on column A1 and works.....

    I can move the colum with second 1 to say C1 etc but I don't know how to move the start to say A12?

    Also I want to add text say "test" so the loop would add 1 test, 2 test etc, can this be done? I knoiw this is a simple loop but I need to get my head around the programming.

    Please Login or Register  to view this content.
    Last edited by DonkeyOte; 02-01-2010 at 08:03 AM. Reason: CODE tags at all times please

  2. #2
    Valued Forum Contributor
    Join Date
    05-14-2009
    Location
    gold coast
    MS-Off Ver
    Excel 2007
    Posts
    843

    Re: Loops with numbers and text basic help

    hello.

    A loop like that will go through each set [i] valve in the above case 1-10 these numbers can be anythink like i = 20 to 40

    so say you want cells A12-A22 fulled

    Please Login or Register  to view this content.
    hope this helps


  3. #3
    Forum Guru DonkeyOte's Avatar
    Join Date
    10-22-2008
    Location
    Northumberland, UK
    MS-Off Ver
    O365
    Posts
    21,531

    Re: Loops with numbers and text basic help

    D_Rennie, I think you need to account for the numeric prefix (ie i-11).

    There are obviously countless ways to do things like this (loop / loop-less) but I agree that understanding loop construct is key.

    v2jtb, please use CODE tags around VBA lines at all times.

  4. #4
    Valued Forum Contributor
    Join Date
    05-14-2009
    Location
    gold coast
    MS-Off Ver
    Excel 2007
    Posts
    843

    Re: Loops with numbers and text basic help

    DonkeyOte, not much passes you up.

    v2jtb. it brings up a good point though using i as a variable can lead to typos, Well atleast for those of us that lack the donkey vison. personally i use X at number variables that are to be used in loops. Though whatever rocks you boat i guess.

    you also mentioned arrays here is a quick look at an array loop
    Please Login or Register  to view this content.
    hope this helps.
    david
    Last edited by D_Rennie; 02-01-2010 at 09:20 AM.

  5. #5
    Registered User
    Join Date
    01-29-2010
    Location
    Scotland
    MS-Off Ver
    Excel 2010
    Posts
    94

    Re: Loops with numbers and text basic help

    Thank you for your help

  6. #6
    Registered User
    Join Date
    01-29-2010
    Location
    Scotland
    MS-Off Ver
    Excel 2010
    Posts
    94

    Re: Loops with numbers and text basic help

    Hi D_Rennie thank you for your help

    The Loop adds 1 Test, to row 12 to 22, how do you get it to count up to sat 10. Like 1 Test, 2 Test etc

    i have tried to add +1 but I am still trying to get the syntax correct. Thank you again

    Please Login or Register  to view this content.

  7. #7
    Registered User
    Join Date
    01-29-2010
    Location
    Scotland
    MS-Off Ver
    Excel 2010
    Posts
    94

    Re: Loops with numbers and text basic help

    Sorry forget that I got it thank you

  8. #8
    Registered User
    Join Date
    01-29-2010
    Location
    Scotland
    MS-Off Ver
    Excel 2010
    Posts
    94

    Re: Loops with numbers and text basic help

    Hi All

    Brilliant I can now add text in front and behind the Loop.
    I now wonder is it possible to add Text in the row above and below the loop can this be done? Like below?

    Image
    Test 1 Test
    Image/
    Image
    Test 2 Test
    Image/

    Please Login or Register  to view this content.

  9. #9
    Valued Forum Contributor
    Join Date
    05-14-2009
    Location
    gold coast
    MS-Off Ver
    Excel 2007
    Posts
    843

    Re: Loops with numbers and text

    hello.

    when looping you can use steep in the loop this can also be used to loop backwards eg for x = 10 to 1 step -1
    Please Login or Register  to view this content.
    there are many ways to do the same thing in vba some stick in the head easer than other thats all.
    If you have any libarys around you see if they can get some books on VBA, VB programming once the basics are understood i found trying to answer question on here realy helps to learn.
    hope this helps
    cheers

+ 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