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 ...
7th April 2008, 12:25 PM #1
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.
7th April 2008, 12:49 PM #2
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
7th April 2008, 12:52 PM #3
Sorry, I am very new to programming how would I do the things you have said.
Can you rewrite the code for me please?
8th April 2008, 12:25 PM #4
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
If this isn't what you want the script to do, can you give a brief explanation of the outcome you expect?
10th April 2008, 08:41 AM #5
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
Did this do the trick?
11th April 2008, 08:08 AM #6
Yes that worked, thanks very much.
By Edu-IT in forum How do you do....it?
Last Post: 7th March 2008, 08:57 AM
By Jackd in forum Web Development
Last Post: 25th November 2007, 12:28 AM
By mmoseley in forum General Chat
Last Post: 23rd November 2007, 06:23 PM
By dan6540 in forum How do you do....it?
Last Post: 20th November 2007, 03:11 PM
By woody in forum Educational Software
Last Post: 14th February 2006, 01:34 PM
Users Browsing this Thread
There are currently 1 users browsing this thread. (0 members and 1 guests)