Я предлагаю использовать пользовательскую форму со списком, в котором вы можете выбрать заголовок.
Вы можете попробовать код ниже.
Требование:
UserForm
Свойство ListBox> Multiselect должно быть = 1
Кнопка> для загрузки выбранных данных на новый лист
Dim mySH As Worksheet
Dim oSH As Worksheet 'Output Worksheet
Private Sub cmd_load_Click()
Dim i As Integer
Dim col_count As Integer
col_count = 1
Dim col_header As String
Dim ns_srow As Integer
ns_srow = 1
'LOOP THRU ALL ITEMS IN LISTBOX AND GET ALL SELECTED
For i = 0 To lst_header.ListCount - 1
If lst_header.Selected(i) Then
col_header = lst_header.List(i)
'FIND THE COLUMN HEADER POSITION AND TRANSFER TO NEWSHEET THE DATA
For a = 1 To mySH.Cells(1, Columns.Count).End(xlToLeft).Column
If mySH.Cells(1, a).Value = col_header Then
For b = 1 To mySH.Cells(Rows.Count, a).End(xlUp).Row
oSH.Cells(ns_srow, col_count).Value = mySH.Cells(b, a).Value
ns_srow = ns_srow + 1
Next b
col_count = col_count + 1
ns_srow = 1
Exit For
End If
Next a
End If
Next i
MsgBox "Data Completed"
End
End Sub
Private Sub UserForm_Initialize()
Set mySH = ThisWorkbook.Sheets("Data") 'name of your raw data worksheet
Set oSH = ThisWorkbook.Sheets("Output") 'output worksheet
'Assuming that column header is at row 1
For a = 1 To mySH.Cells(1, Columns.Count).End(xlToLeft).Column
lst_header.AddItem mySH.Cells(1, a).Value
Next a
End Sub