Microsoft Excel

Excel und VBA: Formeln, Programmierung, Lösungen

Die Excel/VBA-Beispiele

Thema

Tabelle in UserForm-Office-Spreadsheet übernehmen

Gruppe

SpreadSheet

Problem

Die Tabelle2 soll in ein UserForm-Office-Spreadsheet übernommen werden.

Lösung
Geben Sie den nachstehenden Code in das Klassenmodul der UserForm ein.

ClassModule: frmUserTable

Private Sub cmdCancel_Click()
   Unload Me
End Sub

Private Sub UserForm_Initialize()
   Dim rngSource As Range
   Dim rngTarget As Object
   Dim rng As Range
   Set rngSource = Worksheets("Tabelle2").Range("A1").CurrentRegion
   Set rngTarget = Spreadsheet1.Cells.Range(rngSource.Address)
   With Spreadsheet1
      rngTarget.Value = rngSource.Value
   End With
   For Each rng In rngSource.Rows(1).Columns
      rngTarget.Columns(rng.Column).ColumnWidth = rng.Width
   Next rng
End Sub

ClassModule: Tabelle3

Private Sub CommandButton1_Click()
    ActiveCell.Select
    frmUserTable.Show
End Sub

ClassModule: Tabelle1