0

I have a table like this one, and I want to extract the month as a number (1 to 12)

enter image description here

I tried to do something like

For i = 2 To 1165

StartMonth2 = Range("G" & i).Value
StartMonth = Month(StartMonth2)

Next i

but this doesn't work because the month is not part of a date, is just on a column on its own.

I also tried the TEXT formula, something like =TEXT(G2, 'm') but again, the same issue.

Is there a function in VBA that can help me extract the month number easily?

Sam
  • 627
  • 2
  • 13
  • https://learn.microsoft.com/en-us/office/vba/language/reference/user-interface-help/month-function – braX May 22 '23 at 12:35
  • 2
    Do you need VBA? This is easily doable with worksheet formulas. – BigBen May 22 '23 at 12:35
  • @BigBen I could also do it with a formula, how can I do that? – Sam May 22 '23 at 12:36
  • @BigBen this gives me #VALUE! as a formula, and Type mistmach on VBA. Earlier I tried to use the "concat" formula to create the data and it worked in a way, but then when I tried to use the date created on a separate code that checks the date as Cdbl(StartTime) then it wouldn't recognize it as a date. – Sam May 22 '23 at 12:42
  • 2
    Try `=MONTH(1&G2)`. – BigBen May 22 '23 at 12:45
  • Try =LOOKUP(G2;{"Jan";"Feb";"Mar";"Apr";"May" ...."Oct";"Nov";"Dec"}) Month names as in your column ``Month`` – ValNik May 22 '23 at 12:50
  • @BigBen That worked, if you post it as an answer I will select it as the answer to my question. – Sam May 22 '23 at 14:30
  • 1
    Your question is already closed as a duplicate. – BigBen May 22 '23 at 14:31

0 Answers0