0

Part of my sheet name is the date (the part in between the dashes) and I'd like to create a macro that uses the sheet name to give me the number of the week in cell H1 of the sheet.

Sheet name: BO-D58C2_-20180507-13260132

I would like to extract in weeknum to cell H1: 20180507

Do you have any tips for a VBA newbie?

Pᴇʜ
  • 56,719
  • 10
  • 49
  • 73
Jthomson
  • 1
  • 2
  • Have you tried anything yet? Please read the [guide](https://stackoverflow.com/help/asking) on how to ask a good question, while providing a [MCVE](https://stackoverflow.com/help/mcve) example. – Paul Karam May 07 '18 at 13:29
  • 2
    `Cells(i, 8) = Split(Sheets(i).name, "-")(2)` – Scott Craner May 07 '18 at 13:29

2 Answers2

2

use the below function to get the weekdate

Function dydate() As String 
sname = ActiveSheet.Name
dydate = Mid(sname, InStr(sname, "_-") + 2, 8)
End Function
Scott Craner
  • 148,073
  • 10
  • 49
  • 81
hussain s
  • 21
  • 1
0

Range("H1").Value = ActiveSheet.Name

will get the sheets name and put it into a cell for you. From there, you can any number of RegEx and String replaces to extract only the code between the hyphens, and from there convert it to the Week number.

Eric King
  • 103
  • 3
  • 18