anbei Beispiel Datei mit dem Code von Peter(silie) https://www.herber.de/bbs/user/120297.xlsm
Hallo ich habe Zeilen die auf Tabellen Blatt 2 verändert wurden diese sollten auf das Tabellen _
_
blatt 1 überschrieben werden.
In Spalte B auf Tabellen Blatt 1 ist eine Durchnummerierung.
auf diesen Wert soll sich die Übertrag beziehen.
Meine erste Grundfrage. Einen Vergleich mit der Ganzen Spalte B kann ich mir sparen wenn ich _
nur einen Offset nutze oder ist das Unsauberes programmieren?
ich nehme an das muss in einer VBA schleife laufen?
Mein Wunsch in VBA wäre das ich den Code besser verstehe das Jeder spalten wert in der Schleife _
_
eine eigene Variable bekommt
Dim text_a As String
Dim ZeilenNr_b As ingeger
Dim text_c As String
ich konnte kein Beispiel finden aus dem ich etwas ableiten konnte. wahrscheinlich ist es zu _
simpel.
ich hoffe jemand kann mich da unterstützen oder ein passendes Beispiel nennen
danke
gruß chris
Hallo,
Erstelle ein Modul, nenne es wie du möchtest.
Erstelle ein Klassenmodul und nenne es "InformationHandler"
Code des Moduls:
Option Explicit
Sub Execute()
Dim ih As New InformationHandler
Set ih.SuperTable = ThisWorkbook.Sheets("supertabelle")
Set ih.NewTable = ThisWorkbook.Sheets("neue infos")
ih.ExecuteInformationProcessing
End Sub
Code des Klassenmoduls InformationHandler:
Option Explicit
Private Type Information
ID As Long
Type_A As String
Type_C As String
Type_E As String
Type_D As String
Type_F As String
LastChanged As Date
End Type
Private sutable_ As Worksheet
Private newtable_ As Worksheet
Public Property Set SuperTable(ByRef this_ As Worksheet)
Set sutable_ = this_
End Property
Public Property Set NewTable(ByRef this_ As Worksheet)
Set newtable_ = this_
End Property
Public Sub ExecuteInformationProcessing()
Dim NewInformations() As Information
Dim lastRow As Long, i As Long
Dim valueRange As Range, placeToBe As Long
With newtable_
lastRow = .Cells(.Rows.Count, 2).End(xlUp).Row
ReDim NewInformations(lastRow - 4)
For i = 4 To lastRow
NewInformations(i - 4).ID = .Cells(i, 2).Value
NewInformations(i - 4).Type_A = .Cells(i, 1).Value
NewInformations(i - 4).Type_C = .Cells(i, 3).Value
NewInformations(i - 4).Type_D = .Cells(i, 4).Value
NewInformations(i - 4).Type_E = .Cells(i, 5).Value
NewInformations(i - 4).Type_F = .Cells(i, 6).Value
NewInformations(i - 4).LastChanged = .Cells(i, 7).Value
Next i
End With
With sutable_
lastRow = .Cells(.Rows.Count, 2).End(xlUp).Row
Set valueRange = .Range(.Cells(1, 2), .Cells(lastRow, 2))
For i = LBound(NewInformations) To UBound(NewInformations)
placeToBe = Index(valueRange, NewInformations(i).ID)
If placeToBe > 0 Then
.Cells(placeToBe, 1).Value = NewInformations(i).Type_A
.Cells(placeToBe, 3).Value = NewInformations(i).Type_C
.Cells(placeToBe, 4).Value = NewInformations(i).Type_D
.Cells(placeToBe, 5).Value = NewInformations(i).Type_E
.Cells(placeToBe, 6).Value = NewInformations(i).Type_F
.Cells(placeToBe, 7).Value = NewInformations(i).LastChanged
End If
Next i
End With
End Sub
Private Function Index(ByRef area As Range, ID As Long) As Long
If Not VBA.IsError(Application.Match(ID, area, 0)) Then
Index = Application.Match(ID, area, 0)
End If
End Function
der code Funktioniert sehr gut. ich sehe mich aber leider nicht in der Lage den Code nach meinen vorstellungen zu Erweitern.
Ich möchte gerne wenn ich die Zeilen abarbeite noch zusätzlich das aus der "Supertabelle" die Werte aus Spalte H auf das Arbeitsblatt "3tabelle" übertage .
gruß chris
https://www.herber.de/bbs/user/120297.xlsm