Thema Datum  Von Nutzer Rating
Antwort
26.07.2016 07:20:27 Sascha
NotSolved
27.07.2016 21:19:50 Gast50903
NotSolved
01.08.2016 08:12:54 Sascha
NotSolved
Blau Makro erweitern
02.08.2016 23:20:27 Gast94931
NotSolved

Ansicht des Beitrags:
Von:
Gast94931
Datum:
02.08.2016 23:20:27
Views:
674
Rating: Antwort:
  Ja
Thema:
Makro erweitern

Hallo,

okidoki, die Hitzewelle ist vorbei, also hier mal ein zweiter Ansatz, Du hattest jetzt ja idealerweise Daten mitgeliefert, da kann man nach einem zweiten Schlüsselwort ('Instrument') suchen...

Option Explicit

Public Sub test()
  Const LAST_COLUMN As Long = 9  '// Tabellen-Block-Breite SourceSheet
  Const SEARCH_STRING As String = "Objekt" '// Suchtext Tabellenname
  Const SEARCH_STRING_2 As String = "Instrument" '// Suchtext Tabellenende
  Dim wksSheet As Worksheet
  Dim objStartCell As Range, objLastCell As Range
  Dim strChars As String
  Dim lngIndex As Long, lngHeaderColor As Long
  lngHeaderColor = RGB(210, 210, 210) '// Header-Color
  strChars = ": 0" '// Objekt-Bez. SourceSheet
  On Error GoTo Sub_Exit
  Application.ScreenUpdating = False
  Application.DisplayAlerts = False
  For Each wksSheet In ThisWorkbook.Worksheets
     With wksSheet
         If .Name Like SEARCH_STRING & "*" Then Call .Delete
     End With
  Next
  Application.DisplayAlerts = True
  Set wksSheet = ThisWorkbook.Worksheets("ET-Utility Report")
    Do
        lngIndex = lngIndex + 1
        If lngIndex > 9 Then strChars = ": "
              With ThisWorkbook.Worksheets("ET-Utility Report")
                  Set objStartCell = .Cells.Find( _
                      What:=SEARCH_STRING & strChars & lngIndex, LookIn:=xlValues, _
                        LookAt:=xlWhole, MatchCase:=False)
                  If Not objStartCell Is Nothing Then
                    If lngIndex > 8 Then strChars = ": "
                    Set objLastCell = .Cells.Find( _
                      What:=SEARCH_STRING & strChars & lngIndex + 1, LookIn:=xlValues, _
                        LookAt:=xlWhole, MatchCase:=False)
                    If Not objLastCell Is Nothing Then
                      With objStartCell
                            If .Offset(-1, 0).Interior.Color <> lngHeaderColor Then
                              Set objStartCell = .Offset(-2, 0)
                            Else
                              Set objStartCell = .Offset(-1, 0)
                            End If
                      End With
                      Set objLastCell = .Range(objLastCell, objLastCell.Offset(-10, 0)).Find( _
                         What:=SEARCH_STRING_2, LookIn:=xlValues, _
                         LookAt:=xlWhole, SearchDirection:=xlPrevious, MatchCase:=False)
                    Else
                      Set objLastCell = .Range(objStartCell, .Cells(.Cells(.Rows.Count, 2).End(xlUp).Row, _
                         objStartCell.Column)).Find(What:=SEARCH_STRING_2, LookIn:=xlValues, _
                           LookAt:=xlWhole, SearchDirection:=xlPrevious, MatchCase:=False)
                      If Not objLastCell Is Nothing Then
                         Set objStartCell = objStartCell.Offset(-1, 0)
                      Else
                         Call MsgBox("Der Suchwert ist nicht vorhanden....", vbExclamation)
                      End If
                    End If
                      Set wksSheet = ThisWorkbook.Worksheets.Add(After:=wksSheet)
                      With wksSheet
                            .Name = SEARCH_STRING & " " & lngIndex
                            .Columns("B:I").ColumnWidth = 8.88
                            .Columns("J").ColumnWidth = 0.92
                      End With
                      Call .Range(objStartCell, .Cells(objLastCell.Row, LAST_COLUMN + 1)).Copy( _
                          Destination:=wksSheet.Cells(2, 2))
                      Set objLastCell = Nothing
                  End If
              End With
    Loop Until objStartCell Is Nothing
    If lngIndex = 1 Then Call MsgBox("Der Suchwert ist nicht vorhanden....", vbExclamation)
    Call MsgBox("Es wurden " & lngIndex - 1 & " Objekt-Blätter erstellt.", vbExclamation)
Sub_Exit:
    If Err.Number <> 0 Then Call MsgBox("Error: " & _
        Err.Number & " " & Err.Description)
    Set wksSheet = Nothing
    Application.ScreenUpdating = True
    Application.DisplayAlerts = True
End Sub

Gruß,


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
26.07.2016 07:20:27 Sascha
NotSolved
27.07.2016 21:19:50 Gast50903
NotSolved
01.08.2016 08:12:54 Sascha
NotSolved
Blau Makro erweitern
02.08.2016 23:20:27 Gast94931
NotSolved