'Excel: How do I copy and paste ranges into different cells/worksheets based on the real world date?

I have a number worksheets Current Standing, 2022, 2023, 2024 etc

Current standing is just a single range D12:D35 and 2022/3/4 look like this:

enter image description here

I'm trying to copy the range D12:D35 from Current Standing to the current month & year. Current month and year being the literal current real world date.

If I ran the script today it should:

  1. Copy D12:D35 from Current Standing
  2. Paste it into D3/April in the 2022 worksheet.

If I run the script in 3 months (July):

  1. Copy D12:D35 from Current standing
  2. Paste it into G3/July in the 2022 worksheet.

If I run the script in 12 months (April, 2023):

  1. Copy D12:D35 from Current standing
  2. Paste it into D3/April in the 2023 worksheet.

I've managed to figure out how to copy and paste with vba, while protecting and unprotecting the sheet but I'm not sure how I'd take account of the month and year requirement.

Option Explicit
Sub update()

If Worksheets("Current Standing").ProtectContents = True Then

Worksheets("Current Standing").Unprotect
Range("D12:D35").Copy
Range("F12:F35").PasteSpecial xlPasteValues
Worksheets("Current Standing").Protect

Else

Range("D12:D35").Copy
Range("F12:F35").PasteSpecial xlPasteValues
Range("F12:F35").PasteSpecial xlPasteValues
Worksheets("Current Standing").Protect

End If
End Sub


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source