Hallo,
Met onderstaande code verplaats ik data van ene sheet naar andere sheet. ik wil dat de titels van verplaatste gegevens de autofilter pijlen bevatten, zodat ik achteraf de gegevens kan filteren.
kan iemand me hiermee helpen? alvast dank
code:
Met onderstaande code verplaats ik data van ene sheet naar andere sheet. ik wil dat de titels van verplaatste gegevens de autofilter pijlen bevatten, zodat ik achteraf de gegevens kan filteren.
kan iemand me hiermee helpen? alvast dank
code:
Code:
Private Sub cmdLoad_Click()
Dim wsName As String
Dim mySh As Worksheet
Dim newsh As Worksheet
Set newsh = ThisWorkbook.Sheets("rapport")
Set mySh = ThisWorkbook.Sheets("Rapportbron")
Dim countselected As Integer: countselected = 0
Dim col_name As String
Dim col_count As Integer: col_count = 4
Application.ScreenUpdating = False
newsh.Unprotect
newsh.Cells.Clear
newsh.Columns("D:Z").EntireColumn.Delete
newsh.Columns.UseStandardWidth = True
newsh.Rows.UseStandardHeight = True
newsh.Rows.RowHeight = 15
newsh.Columns.ColumnWidth = 8.71
For i = 0 To Me.ListBox2.ListCount - 1
If Me.ListBox2.Selected(i) Then
col_name = Me.ListBox2.List(i)
countselected = countselected + 1
For a = 1 To mySh.Cells(1, Columns.Count).End(xlToLeft).Column
If mySh.Cells(1, a).Value = col_name Then
'copy the data from raw to new worksheet created
For b = 1 To mySh.Cells(Rows.Count, a).End(xlUp).Row
newsh.Cells(b, col_count).Value = mySh.Cells(b, a).Value
'// Autofit Columns
newsh.Cells.EntireColumn.AutoFit
'// Format Table Headers
newsh.Cells(1, col_count).Resize(1, 1).Interior.Color = RGB(233, 233, 233)
newsh.Cells(1, col_count).Resize(1, 1).Font.Bold = True
newsh.Cells(1, col_count).Resize(1, 1).HorizontalAlignment = xlCenter
newsh.Cells(1, col_count).Resize(1, 1).VerticalAlignment = xlBottom
Next b
col_count = col_count + 1
End If
Next a
End If
Next i
Application.ScreenUpdating = True
MsgBox "Data Loaded", vbInformation
newsh.Activate
newsh.Range("C2:G6").Select
Selection.Locked = False
Selection.FormulaHidden = False
newsh.Protect DrawingObjects:=True, Contents:=True, Scenarios:=True _
, AllowFormattingCells:=True, AllowFormattingColumns:=True, _
AllowFormattingRows:=True, AllowSorting:=True, AllowFiltering:=True, _
AllowUsingPivotTables:=True
newsh.Range("D5").Select
End
End Sub
Laatst bewerkt door een moderator: