ebea
Active Member
- Joined
- Jul 12, 2008
- Messages
- 313
- Office Version
- 365
- 2021
- Platform
- Windows
Hi! I run into a problem, with the Offset function, and how to implement it in my code.
In Column H1:FT1 I have month's placed.
What I need to do, is to place the date in F2 in the correct month in the range H2:FT2 (marked in Yellow), when I run my code, from push on Button "Create M.". As now, when I run my code, It place the date in H2.
I have tried many ways around, to get the Offset function, placed correctly in my code, so it ends up in the correct Column, but so far, without any luck.
Hopefully someone have the answer
The code are:
Regards
In Column H1:FT1 I have month's placed.
What I need to do, is to place the date in F2 in the correct month in the range H2:FT2 (marked in Yellow), when I run my code, from push on Button "Create M.". As now, when I run my code, It place the date in H2.
I have tried many ways around, to get the Offset function, placed correctly in my code, so it ends up in the correct Column, but so far, without any luck.
Hopefully someone have the answer

The code are:
VBA Code:
Option Explicit
Sub months()
Dim x As Long
Dim ws As Worksheet
Set ws = Worksheets("Ark1")
ws.Range("H2") = WorksheetFunction.EDate(ws.Range("F2") + 0, 0)
Range("H2").AutoFill Destination:=Range(Cells(2, 8), Cells(2, 8 + Range("G2").Value))
End Sub
Customer | Cost | Sales | Start date | Months period | jan-24 | feb-24 | mar-24 | apr-24 | maj-24 | jun-24 | jul-24 | aug-24 | sep-24 | okt-24 | nov-24 | dec-24 | jan-25 | feb-25 | mar-25 | apr-25 | ||
A | 379,00 | 399,00 | 01-03-2024 | 24 | mar-24 | apr-24 | maj-24 | jun-24 | jul-24 | aug-24 | sep-24 | okt-24 | nov-24 | dec-24 | jan-25 | feb-25 | mar-25 | apr-25 | maj-25 | jun-25 | ||
20 | 20 | 20 | 20 | 20 | 20 | 20 | 20 | 20 | 20 | 20 | 20 | 20 | 20 | 20 | 20 | |||||||
B | 729,00 | 759,00 | 01-02-2024 | 36 | ||||||||||||||||||
C | 449,00 | 459,00 | 01-03-2024 | |||||||||||||||||||
D | 569,00 | 599,00 | 01-04-2024 | |||||||||||||||||||
E | 01-05-2024 | |||||||||||||||||||||
Total | ||||||||||||||||||||||
Regards