+ Reply to Thread
Results 1 to 3 of 3

Creating New Folder via Macro

Hybrid View

  1. #1
    Registered User
    Join Date
    10-13-2010
    Location
    Singapore
    MS-Off Ver
    Excel 2003
    Posts
    82

    Creating New Folder via Macro

    Hello all,
    I found the script below and it creates a folder on Drive C based on the range B9 to B54.

         Dim R As Range
         Dim RootFolder As String
    
         RootFolder = "C:\XXX\ABCDE\"
         For Each R In Range("B9:B54")
             If Len(R.Text) > 0 Then
                 On Error Resume Next
                 MkDir RootFolder & "\" & R.Text
                 On Error GoTo 0
             End If
         Next R
     End Sub
    Can you help me tweak the script so that it reads from B9 all the way to the last line of the column(B)?
    Thank you in advance.
    Last edited by Vincent.Eymard; 10-06-2015 at 12:48 AM.

  2. #2
    Forum Expert skywriter's Avatar
    Join Date
    06-09-2014
    Location
    USA
    MS-Off Ver
    365 Version 2409
    Posts
    2,789

    Re: Creating New Folder via Macro

    See how this works.

     Dim R As Range
         Dim RootFolder As String
         Dim lr As Long
         lr = Cells(Rows.Count, "B").End(xlUp).Row
    
         RootFolder = "C:\XXX\ABCDE\"
         For Each R In Range("B9:B" & lr)
             If Len(R.Text) > 0 Then
                 On Error Resume Next
                 MkDir RootFolder & "\" & R.Text
                 On Error GoTo 0
             End If
         Next R
     End Sub

  3. #3
    Registered User
    Join Date
    10-13-2010
    Location
    Singapore
    MS-Off Ver
    Excel 2003
    Posts
    82

    Re: Creating New Folder via Macro

    Quote Originally Posted by Vincent.Eymard View Post
    Hello all,
    I found the script below and it creates a folder on Drive C based on the range B9 to B54.

         Dim R As Range
         Dim RootFolder As String
    
         RootFolder = "C:\XXX\ABCDE\"
         For Each R In Range("B9:B54")
             If Len(R.Text) > 0 Then
                 On Error Resume Next
                 MkDir RootFolder & "\" & R.Text
                 On Error GoTo 0
             End If
         Next R
     End Sub
    Can you help me tweak the script so that it reads from B9 all the way to the last line of the column(B)?
    Thank you in advance.

    Skywriter, you're a star! Works like a charm! Thank you.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. [SOLVED] Creating a folder for the new year without having to input the folder name.
    By LeapingLizard in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 05-01-2014, 08:09 PM
  2. [SOLVED] Need Help for creating a Macro to extract specific data from all files in a folder.
    By shaiq123 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 03-10-2013, 02:08 PM
  3. Macro for creating folder in teh name of date(15/12/2012)
    By safi0102 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 02-15-2013, 09:55 AM
  4. Creating a Portal to Folder/Files using Macro
    By marshymell0 in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 12-19-2012, 10:54 AM
  5. Creating CULUM results - Folder / Sub Folder from excel macro
    By mash1 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 09-13-2012, 10:19 AM
  6. Creating a folder using macro...
    By ChrisMattock in forum Excel Programming / VBA / Macros
    Replies: 12
    Last Post: 05-25-2006, 12:25 PM
  7. Creating Folder Folder in My Documents VBA - HELP
    By Ali in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 07-25-2005, 10:05 AM

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