Thema Datum  Von Nutzer Rating
Antwort
Rot VBA
25.09.2012 09:39:41 Niklas
NotSolved
Blau VBA
25.09.2012 11:23:30 ferdi
NotSolved
Rot VBA
25.09.2012 13:07:35 Dekor
NotSolved
Blau VBA
25.09.2012 14:37:40 Niklas
NotSolved
Rot VBA
26.09.2012 12:26:28 Dekor
*****
NotSolved
Blau VBA
26.09.2012 12:39:43 Niklas
NotSolved
Rot VBA
26.09.2012 12:53:42 Dekor
NotSolved
Blau VBA
26.09.2012 12:58:04 Niklas
NotSolved
Rot VBA
26.09.2012 13:04:19 Gast14507
NotSolved
Blau VBA
26.09.2012 13:36:09 Niklas
NotSolved
Rot VBA
26.09.2012 20:39:20 Till
NotSolved
Blau VBA
26.09.2012 20:24:58 Dekor
NotSolved
Rot VBA
26.09.2012 20:29:25 Dekor
NotSolved
Blau VBA
26.09.2012 20:50:48 Till
NotSolved
Rot VBA
26.09.2012 21:23:44 Dekor
NotSolved
Blau VBA
27.09.2012 10:05:25 Niklas
NotSolved
Rot VBA
27.09.2012 11:10:10 Till
NotSolved
Blau VBA
27.09.2012 12:32:19 Dekor
NotSolved
Rot VBA
27.09.2012 12:35:04 Dekor
NotSolved
Blau VBA
27.09.2012 13:19:49 Gast88555
NotSolved
Rot VBA
27.09.2012 13:22:02 Niklas
NotSolved
Blau VBA
27.09.2012 16:24:11 Till
NotSolved
Rot VBA
27.09.2012 17:58:26 Niklas
NotSolved
Blau VBA
27.09.2012 18:28:25 Till
NotSolved
Rot VBA
27.09.2012 18:38:03 Niklas
NotSolved
Blau VBA
27.09.2012 18:45:06 Niklas
NotSolved
Rot VBA
27.09.2012 21:23:18 Till
NotSolved
Blau VBA
28.09.2012 09:12:08 Niklas
NotSolved
Rot VBA
28.09.2012 12:42:03 Gast43175
NotSolved
Blau VBA
28.09.2012 09:10:04 Niklas
NotSolved
Rot VBA
28.09.2012 18:17:37 Till
NotSolved
Blau VBA
28.09.2012 19:24:30 Niklas
NotSolved
Rot VBA
28.09.2012 21:16:06 Till
NotSolved
Blau VBA
10.10.2012 11:13:24 Niklas
NotSolved
Rot VBA
11.10.2012 09:27:58 Niklas
NotSolved
Blau VBA
10.10.2012 11:47:12 Gast884
NotSolved
Rot VBA
11.10.2012 06:13:51 Till
NotSolved
Blau VBA
11.10.2012 08:50:55 Niklas
NotSolved
Rot VBA
11.10.2012 09:15:51 Niklas
NotSolved
Blau VBA
12.10.2012 23:55:02 Till
NotSolved
Rot VBA
13.10.2012 22:39:06 Niklas
NotSolved
Blau VBA
14.10.2012 23:47:49 Till
NotSolved
Rot VBA
15.10.2012 09:19:00 Niklas
NotSolved
Blau VBA
15.10.2012 11:34:04 Till
NotSolved
Rot VBA
15.10.2012 13:40:41 Niklas
NotSolved
Blau VBA
15.10.2012 15:15:20 Niklas
NotSolved
Rot VBA
15.10.2012 20:20:40 Till
NotSolved
Blau Blau VBA
15.10.2012 20:25:39 Niklas
NotSolved

Ansicht des Beitrags:
Von:
Till
Datum:
27.09.2012 11:10:10
Views:
1545
Rating: Antwort:
  Ja
Thema:
VBA

Hallo Niklas,

wo ist denn das Problem? Läuft's so nicht?
Kannst die Datei ja irgendwo uploaden und den Linnk hier posten.

Hier mal ein Beispiel für ne Klasse:

In ein Klassenmodul mit dem Namen "Datentransfer":

Option Explicit

Private Zellen() As Range
Private Controls() As Control

Public Bereich As Range
Public UF As UserForm
Public ControlType As String

Sub ZellenEinlesen(rng As Range)
    Dim E1%, E2%
    
    Set Bereich = rng
    If Bereich Is Nothing Then Exit Sub
    With Bereich
        E1 = .Rows.Count
        E2 = .Columns.Count
    End With
    
    ReDim Zellen(E1 * E2 - 1)
    Dim r%, c%, i%
    For r = 1 To E1
        For c = 1 To E2
            Set Zellen(i) = Bereich(r, c)
            i = i + 1
        Next
    Next
End Sub

Sub ControlsEinlesen(ControlNames As String)
    Dim Arr
    Dim E1%, E2%, i%
    
    If InStr(ControlNames, "-") Then
        Arr = Split(ControlNames, "-")
        If UBound(Arr) = 1 Then
            If IsNumeric(Arr(0)) Then
                E1 = Arr(0)
                If IsNumeric(Arr(1)) Then
                    E2 = Arr(1)
                Else: Exit Sub
                End If
            Else: Exit Sub
            End If
            ReDim Controls(E2 - E1)
            Dim j%
            For i = E1 To E2
                Set Controls(j) = UF.Controls(ControlType & i)
                j = j + 1
            Next
        End If
    ElseIf InStr(ControlNames, ",") Then
        Arr = Split(ControlNames, ",")
        E2 = UBound(Arr)
        ReDim Controls(E2)
        For i = 0 To E2
            Set Controls(i) = UF.Controls(ControlType & Arr(i))
        Next
    End If
    
    If IsArray(Controls) Then
        Dim x
        For Each x In Controls
            Debug.Print x.Name
        Next
    End If
    
End Sub

Sub Import()
    Dim i%
    For i = 0 To UBound(Controls)
        Controls(i).Text = Zellen(i)
    Next
End Sub

Sub Export()
    Dim i%
    For i = 0 To UBound(Controls)
        Zellen(i) = Controls(i).Text
    Next
End Sub

Function Überprüfen() As Boolean
    Dim x
    For Each x In Controls
        If x.Text = "" Then
            MsgBox "Bitte " & x.Name & " ausfüllen!"
            Exit Function
        End If
    Next
    Überprüfen = True
End Function

Sub SteuerelementeResetten()
    Dim x As Control
    For Each x In Controls
        x.Text = ""
    Next
End Sub

Und in das Modul der Userform:

Option Explicit

Dim DT As New Datentransfer
Private Sub UserForm_Initialize()
    With DT
        Set .UF = Me
        .ZellenEinlesen Range("E28:G31")
        .ControlType = "TextBox"
        .ControlsEinlesen "2-11"
        .Import
    End With
End Sub
Private Sub UserForm_Activate()
    'Erstes Auswahlfeld Markieren
    With TextBox2
        .SetFocus
        .SelStart = 0
        .SelLength = Len(.Text)
    End With
     
    'Überschrift
    Me.TextBox1.Value = ActiveSheet.Range("B36").Text
     
End Sub
Private Sub CommandButton1_Click()
    With DT
        .ControlsEinlesen "2-13"
        If .Überprüfen Then
            .ControlsEinlesen "2-12"
            .Export
        End If
    End With
    'UF_Tabelle_01.Hide 'hier eintragen
End Sub
Private Sub CommandButton1_MouseMove(ByVal Button As Integer, ByVal Shift As Integer, ByVal x As Single, ByVal Y As Single)
    CommandButton1.SetFocus
End Sub
Private Sub CommandButton2_Click()
    UF_Tabelle_01.Hide 'hier eintragen
End Sub
Private Sub CommandButton2_MouseMove(ByVal Button As Integer, ByVal Shift As Integer, ByVal x As Single, ByVal Y As Single)
    CommandButton2.SetFocus
End Sub
Private Sub CommandButton3_Click()
    DT.Bereich = 0
    Unload Me
    UF_Tabelle_01.Show 'hier eintragen
End Sub
Private Sub CommandButton3_MouseMove(ByVal Button As Integer, ByVal Shift As Integer, ByVal x As Single, ByVal Y As Single)
    CommandButton3.SetFocus
End Sub

'check if value is numeric and stop if it isnt
Private Sub Check(str$, Key As MSForms.ReturnInteger)
    If Not IsNumeric(str & Chr(Key)) Then
        Key = 0
        Beep
    End If
End Sub

Private Sub TextBox2_KeyPress(ByVal KeyAscii As MSForms.ReturnInteger)
    Check ActiveControl.Text, KeyAscii
End Sub
Private Sub TextBox3_KeyPress(ByVal KeyAscii As MSForms.ReturnInteger)
    Check ActiveControl.Text, KeyAscii
End Sub
Private Sub TextBox4_KeyPress(ByVal KeyAscii As MSForms.ReturnInteger)
    Check ActiveControl.Text, KeyAscii
End Sub
Private Sub TextBox5_KeyPress(ByVal KeyAscii As MSForms.ReturnInteger)
    Check ActiveControl.Text, KeyAscii
End Sub
Private Sub TextBox6_KeyPress(ByVal KeyAscii As MSForms.ReturnInteger)
    Check ActiveControl.Text, KeyAscii
End Sub
Private Sub TextBox7_KeyPress(ByVal KeyAscii As MSForms.ReturnInteger)
    Check ActiveControl.Text, KeyAscii
End Sub
Private Sub TextBox8_KeyPress(ByVal KeyAscii As MSForms.ReturnInteger)
    Check ActiveControl.Text, KeyAscii
End Sub
Private Sub TextBox9_KeyPress(ByVal KeyAscii As MSForms.ReturnInteger)
    Check ActiveControl.Text, KeyAscii
End Sub
Private Sub TextBox10_KeyPress(ByVal KeyAscii As MSForms.ReturnInteger)
    Check ActiveControl.Text, KeyAscii
End Sub
Private Sub TextBox11_KeyPress(ByVal KeyAscii As MSForms.ReturnInteger)
    Check ActiveControl.Text, KeyAscii
End Sub
Private Sub TextBox12_KeyPress(ByVal KeyAscii As MSForms.ReturnInteger)
    Check ActiveControl.Text, KeyAscii
End Sub
Private Sub TextBox13_KeyPress(ByVal KeyAscii As MSForms.ReturnInteger)
    Check ActiveControl.Text, KeyAscii
End Sub

 

Insgesamt ist der Code so natürlich länger, macht bei einer einzelnen Userform die nicht zu umfangreich ist nicht so viel Sinn. Sobald du die Klasse und ihr Funktionen mehr als einmal benutzt aber schon, kann man auch noch erweitern...

 

Gruß

Till


Ihre Antwort
  • Bitte beschreiben Sie Ihr Problem möglichst ausführlich. (Wichtige Info z.B.: Office Version, Betriebssystem, Wo genau kommen Sie nicht weiter)
  • Bitte helfen Sie ebenfalls wenn Ihnen geholfen werden konnte und markieren Sie Ihre Anfrage als erledigt (Klick auf Häckchen)
  • Bei Crossposting, entsprechende Links auf andere Forenbeiträge beifügen / nachtragen
  • Codeschnipsel am besten über den Code-Button im Text-Editor einfügen
  • Die Angabe der Emailadresse ist freiwillig und wird nur verwendet, um Sie bei Antworten auf Ihren Beitrag zu benachrichtigen
Thema: Name: Email:



  • Bitte beschreiben Sie Ihr Problem möglichst ausführlich. (Wichtige Info z.B.: Office Version, Betriebssystem, Wo genau kommen Sie nicht weiter)
  • Bitte helfen Sie ebenfalls wenn Ihnen geholfen werden konnte und markieren Sie Ihre Anfrage als erledigt (Klick auf Häckchen)
  • Bei Crossposting, entsprechende Links auf andere Forenbeiträge beifügen / nachtragen
  • Codeschnipsel am besten über den Code-Button im Text-Editor einfügen
  • Die Angabe der Emailadresse ist freiwillig und wird nur verwendet, um Sie bei Antworten auf Ihren Beitrag zu benachrichtigen

Thema Datum  Von Nutzer Rating
Antwort
Rot VBA
25.09.2012 09:39:41 Niklas
NotSolved
Blau VBA
25.09.2012 11:23:30 ferdi
NotSolved
Rot VBA
25.09.2012 13:07:35 Dekor
NotSolved
Blau VBA
25.09.2012 14:37:40 Niklas
NotSolved
Rot VBA
26.09.2012 12:26:28 Dekor
*****
NotSolved
Blau VBA
26.09.2012 12:39:43 Niklas
NotSolved
Rot VBA
26.09.2012 12:53:42 Dekor
NotSolved
Blau VBA
26.09.2012 12:58:04 Niklas
NotSolved
Rot VBA
26.09.2012 13:04:19 Gast14507
NotSolved
Blau VBA
26.09.2012 13:36:09 Niklas
NotSolved
Rot VBA
26.09.2012 20:39:20 Till
NotSolved
Blau VBA
26.09.2012 20:24:58 Dekor
NotSolved
Rot VBA
26.09.2012 20:29:25 Dekor
NotSolved
Blau VBA
26.09.2012 20:50:48 Till
NotSolved
Rot VBA
26.09.2012 21:23:44 Dekor
NotSolved
Blau VBA
27.09.2012 10:05:25 Niklas
NotSolved
Rot VBA
27.09.2012 11:10:10 Till
NotSolved
Blau VBA
27.09.2012 12:32:19 Dekor
NotSolved
Rot VBA
27.09.2012 12:35:04 Dekor
NotSolved
Blau VBA
27.09.2012 13:19:49 Gast88555
NotSolved
Rot VBA
27.09.2012 13:22:02 Niklas
NotSolved
Blau VBA
27.09.2012 16:24:11 Till
NotSolved
Rot VBA
27.09.2012 17:58:26 Niklas
NotSolved
Blau VBA
27.09.2012 18:28:25 Till
NotSolved
Rot VBA
27.09.2012 18:38:03 Niklas
NotSolved
Blau VBA
27.09.2012 18:45:06 Niklas
NotSolved
Rot VBA
27.09.2012 21:23:18 Till
NotSolved
Blau VBA
28.09.2012 09:12:08 Niklas
NotSolved
Rot VBA
28.09.2012 12:42:03 Gast43175
NotSolved
Blau VBA
28.09.2012 09:10:04 Niklas
NotSolved
Rot VBA
28.09.2012 18:17:37 Till
NotSolved
Blau VBA
28.09.2012 19:24:30 Niklas
NotSolved
Rot VBA
28.09.2012 21:16:06 Till
NotSolved
Blau VBA
10.10.2012 11:13:24 Niklas
NotSolved
Rot VBA
11.10.2012 09:27:58 Niklas
NotSolved
Blau VBA
10.10.2012 11:47:12 Gast884
NotSolved
Rot VBA
11.10.2012 06:13:51 Till
NotSolved
Blau VBA
11.10.2012 08:50:55 Niklas
NotSolved
Rot VBA
11.10.2012 09:15:51 Niklas
NotSolved
Blau VBA
12.10.2012 23:55:02 Till
NotSolved
Rot VBA
13.10.2012 22:39:06 Niklas
NotSolved
Blau VBA
14.10.2012 23:47:49 Till
NotSolved
Rot VBA
15.10.2012 09:19:00 Niklas
NotSolved
Blau VBA
15.10.2012 11:34:04 Till
NotSolved
Rot VBA
15.10.2012 13:40:41 Niklas
NotSolved
Blau VBA
15.10.2012 15:15:20 Niklas
NotSolved
Rot VBA
15.10.2012 20:20:40 Till
NotSolved
Blau Blau VBA
15.10.2012 20:25:39 Niklas
NotSolved