Results 1 to 8 of 8

Using loops in VBA

Threaded View

  1. #1
    Registered User
    Join Date
    05-01-2012
    Location
    Australia
    MS-Off Ver
    excel 2010
    Posts
    7

    Using loops in VBA

    I had a look and got some answers. I have found out how to get into the VB code and create a command button. I want to get a series of numbers across a row (say, 1 to ten), with an empty cell between each number. I wrote this code line to get my first number:
    Sheet1.cells(10,5) = "1"
    and that worked, so i copied 9 more times and just changed the cell number and the number i wanted in it, eg
    Sheet1.cells(10,7) = "2"
    and that worked of course, but is obviously tedious and ridiculously slow if i wanted 1 to 100

    So, sorry for the simple question: but how do i get it to do a whole series of numbers with one command? I tried
    Sheet1.cells(10,5 to 15) = "1 to 10"
    and it didn't work. Tried dashes instead of the word to... then thought, oh heck, stupid as it looks in a forum, I'm going to ask... I'm thinking there is an If loop that would do it for me... am i on the right track?
    Last edited by Paul; 05-08-2012 at 05:54 PM. Reason: Added CODE tags. Please do so yourself in the future.

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