Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7797571
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T23:43:37+00:00 2026-06-01T23:43:37+00:00

I need to convert a string variable to a date variable in a VBA

  • 0

I need to convert a string variable to a date variable in a VBA macro, to process the date to get the mMonth and year in order to name the worksheet

Call GetMonthandYear(MonthYear, FileDate)
    ActiveSheet.Name = MonthYear

I looking to create a method called GetMonthandYear. FileDate is a String in a date format, dd.MM.yyyy HH-mm-ss. If I can change the variable to a date, I can change the format to MMMM/yyyy and then use ToString, I think, and assign it to MonthYear.

Is there a way to change the string to a date?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T23:43:38+00:00Added an answer on June 1, 2026 at 11:43 pm

    There are several problems with your proposed aaproach:

    1. Converting strings to date serial can be problematic, with uncertanty if Excel will interpret the date as dd.MM or MM.dd. Since you know the format in advance, extract the month and year directly.
    2. \ is not a valid character for sheet names. I’ve used _, substitute as you wish

    Function GetMonthandYear(FileDate As String) As String
        Dim dot1 As Long, dot2 As Long
        Dim m As String, y As String
    
        dot1 = InStr(FileDate, ".")
        dot2 = InStr(dot1 + 1, FileDate, ".")
        m = Mid$(FileDate, dot1 + 1, dot2 - dot1 - 1)
        y = Mid$(FileDate, dot2 + 1, InStr(FileDate, " ") - dot2 - 1)
    
        GetMonthandYear = Format$(DateSerial(y, m, 1), "MMMM_yyyy")
    End Function
    

    Call it like this

    Sub Test()
        Dim FileDate As String
        FileDate = "15.04.2012 16-31-18"
    
        ActiveSheet.Name = GetMonthandYear(FileDate)
    
    End Sub
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

<xsl:variable name=string select='abcdefghijklmnopqrstuvwxyz' /> I would need to convert this string to a node,
I need to convert from a SQLVARCHAR to a string data type Variable definitions
I need to convert my string date to datetime type. Here's one date scenario:
I need to convert a timestamp string to java.util.Date . E.g.: MMDDYYHHMMSS to MM-DD-YY
I need to convert a date to a string. The date is entered as
I need help converting a DATE format to STRING format. I have a variable
I have a string variable called tbSKUPrice. I need to convert this into an
I need to convert String to the date on one of the xml nodes
Problem I need to convert two ints and a string of variable length to
I am working on a tool where I need to convert string values to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.