Wildcard character for vba

dpaton05

Well-known Member
Joined
Aug 14, 2018
Messages
2,352
Office Version
  1. 365
  2. 2016
Platform
  1. Windows
I have a spreadsheet that has a button to create a new document for a new financial year. There is a text box where the new financial year will be entered in. I did have it so the new document could be created but only for the following financial year to the current one. Then my supervisor told me he might want to create the document and it may be for any given year, not just the subsequent. I started to change my code but then got stuck. This is the first part of my code that works:

Code:
Private Sub cmdNewYear_Click()

Dim newDoc As String
Dim NewDocYear As Integer


    'Worksheets("home").Unprotect Password:="costings"
    NewDocYear = txtYear.Value
    newDoc = "NPSS work allocation sheet " & NewDocYear & " - " & NewDocYear + 1 & ".xlsm"

    'ActiveWorkbook.Save
    ActiveWorkbook.SaveCopyAs ThisWorkbook.Path & "\" & newDoc
    Workbooks.Open Filename:=ThisWorkbook.Path & "\" & newDoc
    'Workbooks("NPSS work allocation sheet " & year(Now) + 1 &  ".xlsm").Worksheets("home").Unprotect Password:="costings"
    
    With Workbooks("NPSS work allocation sheet " & NewDocYear & " - " & NewDocYear + 1 & ".xlsm").Sheets("home")
        .Range("A18") = "July " & NewDocYear
        .Range("A19") = "August " & NewDocYear
        .Range("A20") = "September " & NewDocYear
        .Range("A21") = "October " & NewDocYear
        .Range("A22") = "November " & NewDocYear
        .Range("A23") = "December " & NewDocYear
        .Range("E18") = "January " & NewDocYear + 1
        .Range("E19") = "February " & NewDocYear + 1
        .Range("E20") = "March " & NewDocYear + 1
        .Range("E21") = "April " & NewDocYear + 1
        .Range("E22") = "May " & NewDocYear + 1
        .Range("E23") = "June " & NewDocYear + 1
    End With

I didn't know how to get the sheet names to change to have the new year reflected. Here is part of the rest of my code:

Code:
      With Workbooks(newDoc)
        .Sheets("July " & NewDocYear).Name = "July " & year(Now)
            With Sheets("July " & year(Now))
                .Range("A4:E2000").Clear
                .Range("A1").Value = "501 NPSS " & "July " & year(Now)
            End With
            
        .Sheets("August " & Range("D1")).Name = "August " & year(Now)
            With Sheets("August " & year(Now))
                .Range("A4:E2000").Clear
                .Range("A1").Value = "501 NPSS " & "August " & year(Now)
            End With

I tried changing the NewYearDoc but it wouldn't work. The second part, relating the the august sheet, is how it used to be.


D1 had this formula
Code:
=YEAR(TODAY())-1

How do I get the sheet names to change from the current year in the document to the new year. It could be created from any year document.

Thanks,
Dave
 

Excel Facts

Select a hidden cell
Somehide hide payroll data in column G? Press F5. Type G1. Enter. Look in formula bar while you arrow down through G.

Forum statistics

Threads
1,214,522
Messages
6,120,022
Members
448,939
Latest member
Leon Leenders

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top