+ Reply to Thread
Results 1 to 5 of 5

Automated sheets naming

Hybrid View

kris82 Automated sheets naming 03-14-2016, 11:31 AM
walruseggman Re: Automated sheets naming 03-14-2016, 12:13 PM
kris82 Re: Automated sheets naming 03-15-2016, 04:19 AM
walruseggman Re: Automated sheets naming 03-15-2016, 11:38 AM
kris82 Re: Automated sheets naming 03-16-2016, 04:17 AM
  1. #1
    Registered User
    Join Date
    03-14-2016
    Location
    Warsaw
    MS-Off Ver
    2010
    Posts
    11

    Automated sheets naming

    Hi,

    my macro code:


    Sub MAKRO() 
    
    Close #1 
    plik_txt = Application.GetOpenFilename("Pliki txt(*.csv;*.txt),*.csv;*.txt") 
    Open plik_txt For Input As #1 
    'Open ".\dane.txt" For Input As #1 
    
    wrs = 1 
    Do Until EOF(1) 
    kol = 1 
    Line Input #1, textline
    tbl = Split(textline, ",") 
    For i = 0 To UBound(tbl) 
    Cells(wrs, kol) = tbl(i) 
    kol = kol + 1 
    Next 
    wrs = wrs + 1 
    Loop 
    For j = 1 To wrs - 1 
    Dim iname As String 
    Sheets.Add After:=Sheets(Sheets.Count) 
    'iname = Chr(34) & "Sheet" & i & Chr(34) 
    iname = "Sheet" & j 
    Sheets(iname).Select 
    'Sheets("iname").Name = "aaa" 
    Next j 
    Close #1
    Problem:
    Iname can't be understood by Sheets(iname).Select. As you can see I tried to add special signs to simply read correct name, but VBA don't get it.

    This code part is opening external file *.txt, which contains in column names, ie:
    WIERSZ1
    WIERSZ2
    WIERSZ3
    WIERSZ4
    ....

    I would like to add sheets which names are as in external file. My idea was to open this file, read rows, create sheets and rename them. After that I would read to those worksheets data from other files I have and which names are: WIERSZ1.csv, WIERSZ2.csv, WIERSZ3.csv... but just wondering if this code is not too sophisticated and if there's no easier way to achieve the same result in few lines.
    Thanks for help.

  2. #2
    Forum Expert
    Join Date
    08-28-2014
    Location
    Texas, USA
    MS-Off Ver
    2016
    Posts
    1,796

    Re: Automated sheets naming

    Iname can't be understood by Sheets(iname).Select.
    Because you never actually named a sheet iname. Try something like:

    Set ws = Sheets.Add After:=Sheets(Sheets.Count)
    ws.Name = Chr(34) & "Sheet" & i & Chr(34)
    Or whatever you're trying to have the sheets be named.
    I'm interested in starting a career working with VBA, if anyone knows of any opportunities!

  3. #3
    Registered User
    Join Date
    03-14-2016
    Location
    Warsaw
    MS-Off Ver
    2010
    Posts
    11

    Re: Automated sheets naming

    Quote Originally Posted by walruseggman View Post
    Because you never actually named a sheet iname. Try something like:

    Set ws = Sheets.Add After:=Sheets(Sheets.Count)
    ws.Name = Chr(34) & "Sheet" & i & Chr(34)
    Or whatever you're trying to have the sheets be named.
    Now Excel see problem in After:=Sheets(Sheets.Count)

  4. #4
    Forum Expert
    Join Date
    08-28-2014
    Location
    Texas, USA
    MS-Off Ver
    2016
    Posts
    1,796

    Re: Automated sheets naming

    My bad, should be in parenthesis:

    (After:=Sheets(Sheets.Count))

  5. #5
    Registered User
    Join Date
    03-14-2016
    Location
    Warsaw
    MS-Off Ver
    2010
    Posts
    11

    Re: Automated sheets naming

    Quote Originally Posted by walruseggman View Post
    My bad, should be in parenthesis:

    (After:=Sheets(Sheets.Count))
    Thank you. I solve issue by making sheet with names active and then:

    Sheets.Add After:=Sheets(Sheets.Count)
    ActiveSheet.Name = Sheets("paths_names").Cells(j, 1).Value

+ 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. Need help with copying rows, replicating sheets, naming sheets and assigning print area...
    By Navin Agrawal in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 09-05-2014, 09:21 AM
  2. Automated Tab (Sheet) Naming
    By Hindsight81 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 10-23-2012, 02:50 PM
  3. Re-Naming Sheets per Cell data & Hiding Sheets
    By dej222 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 08-26-2009, 10:20 PM
  4. The Naming of sheets
    By tuganne1 in forum Excel General
    Replies: 3
    Last Post: 04-30-2009, 05:48 PM
  5. Automated Exporting Sheets?
    By thomas.szwed in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 11-28-2007, 07:44 AM
  6. Naming Sheets
    By Dallas6570 in forum Excel Programming / VBA / Macros
    Replies: 11
    Last Post: 11-16-2007, 11:49 AM
  7. naming sheets
    By Christian Galbavy in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 05-16-2005, 06:06 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