I've got a set of named ranges on a worksheet which hold summary data from other tabs (one for each month). The ranges are named JAN / FEB / MAR etc. My file contains various reports which compare one month with another and to make this dynamic I need users to be able to compare any two months.
The reports run off a separate sheet which has a pasted (values) version of which ever months summary data you need, so essentially I want a macro with a user form that allows a user to select a month then it will find that range, copy it and paste it in the sheet that drives the report. I've managed to do something similar based on sheet names (see code below) but I can't get anything to work for named ranges.
Any help gladly appreciated, I'm very much a self educated amateur at all this.
Private Sub CommandButton1_Click()
Dim i As Integer, sht As String
For i = 0 To ListBox1.ListCount - 1
If ListBox1.Selected(i) = True Then
sht = ListBox1.List(i)
End If
Next i
Sheets(sht).Range("A4:C15").Copy
Sheets("Sheet1").Select.Range("N1").PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Application.CutCopyMode = False
End
End Sub
Private Sub CommandButton2_Click()
Unload UserForm2
End Sub
Private Sub ListBox1_Click()
End Sub
Private Sub UserForm_Initialize()
Dim ws As Worksheet
For Each ws In ThisWorkbook.Worksheets
ListBox1.AddItem (ws.Name)
Next ws
End Sub