+ Post New Thread
Results 1 to 6 of 6
Coding Thread, Excel VBA Loop Question in Coding and Web Development; This is my current code, how can I change the range to E9,E10 and onward to continue the code until ...
  1. #1
    vunsev's Avatar
    Join Date
    Feb 2008
    Posts
    18
    Thank Post
    4
    Thanked 0 Times in 0 Posts
    Rep Power
    0

    Excel VBA Loop Question

    This is my current code, how can I change the range to E9,E10 and onward to continue the code until the range cell is empty.

    Dim Cellname As String
    Dim rng As Range

    Set rng = Sheets("CPD").Range("E8")
    Cellname = rng.Text

    MkDir "C:\Documents and Settings\administrator.BILLESLEY1\Desktop\CPD\" & Cellname

    Any help would be greatful.

  2. #2
    penfold_99's Avatar
    Join Date
    Feb 2008
    Location
    East Sussex
    Posts
    1,003
    Thank Post
    60
    Thanked 167 Times in 119 Posts
    Rep Power
    69
    Hi

    you need to create a loop either a while or for
    it will increment a value eg counter

    then reference the field by

    Set rng = Sheets("CPD").Range("E" & counter)

    as part of the loop or as an if statement inside the loop, check if the cell conatins anything if not exit the loop

  3. #3
    vunsev's Avatar
    Join Date
    Feb 2008
    Posts
    18
    Thank Post
    4
    Thanked 0 Times in 0 Posts
    Rep Power
    0
    Sorry, I am very new to programming how would I do the things you have said.

    Can you rewrite the code for me please?

  4. #4
    Shane's Avatar
    Join Date
    Apr 2007
    Location
    Kernow
    Posts
    166
    Thank Post
    23
    Thanked 14 Times in 12 Posts
    Rep Power
    22
    go = 1
    counter = 1

    While go = 1
    Sheets("CPD").Range("E" & counter).Select
    contents = ActiveCell.Value
    If contents = "" Then go = 0
    counter = counter + 1

    MkDir "C:\Documents and Settings\administrator.BILLESLEY1\Desktop\CPD\" & contents

    Wend

    If this isn't what you want the script to do, can you give a brief explanation of the outcome you expect?
    Cheers

  5. Thanks to Shane from:

    vunsev (11th April 2008)

  6. #5
    Shane's Avatar
    Join Date
    Apr 2007
    Location
    Kernow
    Posts
    166
    Thank Post
    23
    Thanked 14 Times in 12 Posts
    Rep Power
    22
    sw = 1

    While Range("e" & sw) <> ""
    Range("e" & sw).Select
    person = ActiveCell.Value
    Range("d" & sw).Select
    course = ActiveCell.Value

    Set fs = CreateObject("Scripting.FileSystemObject")
    If fs.FolderExists("c:\" & person) = False Then fs.CreateFolder ("c:\" & person)
    fs.createtextfile ("c:\" & person & "\" & course & ".txt")

    sw = sw + 1
    Wend

    Did this do the trick?
    Cheers

  7. Thanks to Shane from:

    vunsev (11th April 2008)

  8. #6
    vunsev's Avatar
    Join Date
    Feb 2008
    Posts
    18
    Thank Post
    4
    Thanked 0 Times in 0 Posts
    Rep Power
    0
    Yes that worked, thanks very much.



SHARE:
+ Post New Thread

Similar Threads

  1. Excel
    By Edu-IT in forum How do you do....it?
    Replies: 13
    Last Post: 7th March 2008, 09:57 AM
  2. PHP Loop Table
    By Jackd in forum Web Development
    Replies: 2
    Last Post: 25th November 2007, 01:28 AM
  3. Sony StorStation Log on/off loop
    By mmoseley in forum General Chat
    Replies: 0
    Last Post: 23rd November 2007, 07:23 PM
  4. Powerpoint Playlist loop
    By dan6540 in forum How do you do....it?
    Replies: 2
    Last Post: 20th November 2007, 04:11 PM
  5. RANDBETWEEN in MS Excel
    By woody in forum Educational Software
    Replies: 3
    Last Post: 14th February 2006, 02:34 PM

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •