+ Reply to Thread
Results 1 to 4 of 4

Creating a new sheet with specific formatting using excel VBA

  1. #1
    Registered User
    Join Date
    08-20-2019
    Location
    Derby, England
    MS-Off Ver
    2016
    Posts
    7

    Creating a new sheet with specific formatting using excel VBA

    Hi,

    I have a macro button which upon clicking creates a new sheet titled with the current date. I would like the sheet to be created with a specific formatting (the same formatting for every new sheet created). I suppose this may be linked to creating a template but I'm not sure how best to do this. Would it also be possible to maybe along with the code for creating a new sheet to add in specific formatting commands such as making column C a certain width etc or cell D3 the colour red (all for example). I am trying to design the workbook to be able to be accessible via the cloud so would going down the template route cause issues (in terms of searching for the template directory?).

    Many Thanks,

  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: Creating a new sheet with specific formatting using excel VBA

    As far as I'm aware the free version of Office 365 Excel does not allow macros.

    The obvious choice is as you say to develop a fully formatted template sheet (which could be hidden) and the when your macro copies it have some code that varies the stuff you're interested in in respose to user inputs.
    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
    08-20-2019
    Location
    Derby, England
    MS-Off Ver
    2016
    Posts
    7

    Re: Creating a new sheet with specific formatting using excel VBA

    I have tried to do as you suggested but I am now having issues with my current code:

    Private Sub cmdShowForm_Click()

    Dim a As String
    Dim exists As Boolean
    Dim sh As Worksheet

    For i = 1 To Worksheets.Count
    If Worksheets(i).Name = Date$ Then
    exists = True
    Else
    exists = False
    End If
    Next i

    If exists = False Then
    Sheets("TEMPLATE").Copy after:=Sheets(Sheets.Count)
    ActiveSheet.Name = Date$ (<- ISSUE IS HIGHLIGHTED HERE BY THE VBA EDITOR)
    Set sh = ActiveSheet
    ElseIf exists = True Then
    ThisWorkbook.Sheets(Date$).Activate
    End If

    End Sub

    The sub routine does effectively create a new sheet with the current date however upon revisiting the sub (by clicking the button) a new sheet is created titled ("TEMPLATE(2)") and an error is highlighted in the code. How can I get it to work? I want it to check through the sheets to detect if a sheet exists that is titled by the current date. If there isn't one I want one to be created that is titled by the current date and follows the format from the "TEMPLATE" sheet. If one does already exist (i.e the button is clicked more than once in a day) I want it to go straight to that sheet and not create anything more.

    Any help would be greatly appreciated!

  4. #4
    Forum Guru
    Join Date
    09-10-2017
    Location
    Chippenham, England
    MS-Off Ver
    365
    Posts
    15,077

    Re: Creating a new sheet with specific formatting using excel VBA

    How about
    Please Login or Register  to view this content.
    change format in red to your preference.

+ 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 macro to populate specific cells from master sheet to work sheet
    By tatyanamarie in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 05-01-2017, 03:19 AM
  2. Creating an addins menu bar on a specific session/sheet
    By scottiex in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 11-08-2016, 02:23 AM
  3. [SOLVED] Creating a search method in an excel sheet to identify things according to a specific id.
    By Moh13 in forum Excel Programming / VBA / Macros
    Replies: 28
    Last Post: 10-02-2013, 11:40 PM
  4. Creating an automatic move to another sheet when a specific option is chosen from list
    By morgangallo in forum Excel Programming / VBA / Macros
    Replies: 10
    Last Post: 08-15-2013, 08:36 AM
  5. Replies: 5
    Last Post: 05-18-2013, 08:32 PM
  6. Creating Macro to copy excel sheet from workbook1 and past into excel sheet workbook2
    By t_gagliardi in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 08-06-2012, 01:19 PM
  7. Replies: 0
    Last Post: 04-21-2011, 09:20 AM

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