+ Reply to Thread
Results 1 to 8 of 8

VBA macro problem regarding folder generating

  1. #1
    Registered User
    Join Date
    07-20-2015
    Location
    Budapest
    MS-Off Ver
    2013
    Posts
    4

    Unhappy VBA macro problem regarding folder generating

    Hi,

    I am trying to make an excel sheet with a macro. The goal would be if I click on a cell and then on a button (with a macro assigned to it) it would create a folder to a specific place with the name of the cell.

    However I would it like this: if I click on the Rng(r,c) cell, it should create the folder with a name of this cell value and to a place which is in the (r, c=c-3) cell. But unfortunately I couldn't find out how to refer to a columns value next to another column by 3 columns.

    Example:
    D1 cell: file://\\network_folder\subfolder\
    D4 cell: 45678

    So if there is 45678 in D4 cell, then after starting the macro it would create a folder named 45678 to the place of D1 so I can find my new folder: \\network_folder\subfolder\45678

    Here is the macro, I highlighted the part which is wrong now, and maybe i shouldn't use Range function?


    Please Login or Register  to view this content.
    Thank you in advance very much!

    Regards,
    István
    Last edited by istvanvincze90; 07-20-2015 at 08:20 AM. Reason: code tags

  2. #2
    Forum Moderator - RIP Richard Buttrey's Avatar
    Join Date
    01-14-2008
    Location
    Stockton Heath, Cheshire, UK
    MS-Off Ver
    Office 365, Excel for Windows 2010 & Excel for Mac
    Posts
    29,464

    Re: VBA macro problem regarding folder generating

    Hi and welcome to the forum. Unfortunately your post does not comply with Rule 3 of our Forum RULES. Use code tags around code.

    Posting code between [CODE]Please [url=https://www.excelforum.com/login.php]Login or Register [/url] to view this content.[/CODE] tags makes your code much easier to read and copy for testing, it also maintains VBA formatting.

    Highlight your code and click the # icon at the top of your post window. More information about these and other tags can be found here



    (This thread should receive no further responses until this moderation request is fulfilled, as per Forum Rule 7)
    Richard Buttrey

    RIP - d. 06/10/2022

    If any of the responses have helped then please consider rating them by clicking the small star icon below the post.

  3. #3
    Registered User
    Join Date
    07-20-2015
    Location
    Budapest
    MS-Off Ver
    2013
    Posts
    4

    Re: VBA macro problem regarding folder generating

    hello, thanks, it is done, hope it's ok now.

  4. #4
    Valued Forum Contributor bulina2k's Avatar
    Join Date
    11-20-2012
    Location
    Urziceni, Ialomita, Romania
    MS-Off Ver
    2019 and 365
    Posts
    861

    Re: VBA macro problem regarding folder generating

    i don't know why all the loops but i would do it this way:
    Please Login or Register  to view this content.
    .. and don't forget to have fun!
    Bogdan.

    mark SOLVED and Add Reputation if my answer pleases you

  5. #5
    Registered User
    Join Date
    07-20-2015
    Location
    Budapest
    MS-Off Ver
    2013
    Posts
    4

    Re: VBA macro problem regarding folder generating

    Thank you!
    Where should I put it this private sub?
    And target count means if the range involves more than 1 cell?

  6. #6
    Valued Forum Contributor bulina2k's Avatar
    Join Date
    11-20-2012
    Location
    Urziceni, Ialomita, Romania
    MS-Off Ver
    2019 and 365
    Posts
    861

    Re: VBA macro problem regarding folder generating

    You can paste the code on the VB editor (Alt+F11) after double clicking the SheetName (alternatively you can right click and select View Code)
    Please Login or Register  to view this content.

  7. #7
    Registered User
    Join Date
    07-20-2015
    Location
    Budapest
    MS-Off Ver
    2013
    Posts
    4

    Re: VBA macro problem regarding folder generating

    Great, I suspected it, but now it is clear! Thank you!

    I meant my question where shall I copy it in VBA? To a new module? Or to the original Sub, after the End Sub?
    Or inside the original code?

  8. #8
    Valued Forum Contributor bulina2k's Avatar
    Join Date
    11-20-2012
    Location
    Urziceni, Ialomita, Romania
    MS-Off Ver
    2019 and 365
    Posts
    861

    Re: VBA macro problem regarding folder generating

    Not in a module, not in the original Sub. The code is executed each time you change the selection so it is an event triggered code. Worksheet SelectionChange procedure is installed with the worksheet, ie. it must be placed in the code module of the appropriate Sheet object. To create a worksheet SelectionChange event: use the Visual Basic Editor -> in the Project Explorer, double click on the appropriate sheet (under 'Microsoft Excel Objects' which is under the VBAProject/name of your workbook) -> in the Code window paste the provided code.

+ 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. Problem with a macro generating a msgbox instruction
    By Johnb11 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 11-19-2014, 07:07 PM
  2. Generating a csv in the same folder as spreadsheet using VBA
    By babytigress in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 03-05-2014, 08:19 PM
  3. problem with macro - trying to extract subjects from .msg files stored in folder
    By mwilkes in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 12-10-2013, 07:06 PM
  4. problem with generating new worksheet in macro and transferring values
    By benniboi in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 07-29-2012, 07:42 AM
  5. Problem with generating Combinations (Myrna Larson macro)
    By Excelstudent12 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 01-20-2012, 04:28 AM
  6. Bizarre problem assigning macro to object; works in one folder, not another.
    By jdsmithks in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 06-30-2009, 04:50 PM

Tags for this Thread

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