Thema Datum  Von Nutzer Rating
Antwort
22.05.2014 10:05:48 HR
NotSolved
22.05.2014 15:30:55 Amicro2000
NotSolved
22.05.2014 19:19:51 Gast64552
NotSolved
22.05.2014 19:25:42 Gast19909
NotSolved
Rot Komplett mir überarbeiteter GAForm
22.05.2014 20:50:25 Gast60763
*****
Solved
23.05.2014 13:10:06 HR
NotSolved
23.05.2014 13:31:25 Gast24605
*****
Solved
23.05.2014 13:10:06 HR
NotSolved
23.05.2014 16:50:19 HR
NotSolved
23.05.2014 17:15:11 Gast66050
Solved

Ansicht des Beitrags:
Von:
Gast60763
Datum:
22.05.2014 20:50:25
Views:
2017
Rating: Antwort:
 Nein
Thema:
Komplett mir überarbeiteter GAForm
Option Explicit

Public Sub SplitWorksheetByStoreID()
   
  If ActiveSheet Is Nothing Then Exit Sub
  If Not TypeOf ActiveSheet Is Excel.Worksheet Then Exit Sub
   
  If vbCancel = MsgBox("Die Daten, auf dem Aktiven Blatt, werden nun nach der 'store_id' aufgesplittet.", _
                        vbQuestion Or vbOKCancel Or vbDefaultButton2) _
  Then
    Exit Sub
  End If
   
  On Error GoTo ErrHandler
  
  Application.ScreenUpdating = False
   
  Dim wksDst As Excel.Worksheet
  Dim i As Long, j As Long
   
  With ActiveSheet.UsedRange.CurrentRegion
    
    If .Columns.Count < 4 Then
      Call MsgBox("Keine Daten vorhanden.", vbExclamation)
      GoTo SafeExit
    End If
    
    If .Cells(2, 4).Value = WorksheetFunction.Average(.Columns(4)) Then
      Call MsgBox("Falsches Blatt aktiv.", vbExclamation)
      GoTo SafeExit
    End If
    
    Call .Sort(Key1:=.Cells(1, "D"), Order1:=xlAscending, Header:=xlYes)
     
    i = 2
    Do Until i > .Rows.Count
       
      j = i
      Do While .Cells(i, "D") = .Cells(j + 1, "D")
        j = j + 1
      Loop
       
      If WorksheetExists(.Cells(i, "D").Text) Then
        Set wksDst = Worksheets(.Cells(i, "D").Text)
        Call wksDst.UsedRange.Delete
      ElseIf Not wksDst Is Nothing Then
        Set wksDst = ThisWorkbook.Worksheets.Add(After:=wksDst)
        wksDst.Name = .Cells(i, "D").Text
      Else
        Set wksDst = ThisWorkbook.Worksheets.Add(After:=.Worksheet)
        wksDst.Name = .Cells(i, "D").Text
      End If
      
      Call Union(.Rows(1), .Worksheet.Range(.Rows(i), .Rows(j))).Copy
      With wksDst.Range("A1")
        Call .PasteSpecial(xlPasteColumnWidths)
        Call .PasteSpecial(xlPasteValuesAndNumberFormats)
      End With
      
      Call GAForm(wksDst)
      
      i = j + 1
    Loop
     
    Call .Worksheet.Activate
     
  End With
   
  Call MsgBox("Vorgang erfolgreich abschlossen.", _
              vbInformation, _
              "Erfolg")
   
SafeExit:
  Application.CutCopyMode = False
  Application.ScreenUpdating = True
Exit Sub
 
ErrHandler:
  Call MsgBox(Err.Description, _
              vbCritical, _
              "Fehler " & Err.Number)
  GoTo SafeExit
End Sub

Private Sub GAForm(Worksheet As Excel.Worksheet)
  
  Dim rng As Excel.Range
  Set rng = Worksheet.UsedRange.CurrentRegion
  
  If rng.Rows.Count = 1 _
    Then Exit Sub
  
  If Not ActiveSheet Is Worksheet _
    Then Worksheet.Activate
  
  'Datenbereich inkl. neue Summe-Zeile
  With rng.Resize(rng.Rows.Count + 1)
    
    'Kopfzeile
    With rng.Rows(1)
      Call .Clear
      .Font.Bold = True
      .Resize(ColumnSize:=3).Value = Array("Datum", "Code", "Wert")
    End With
    
    'neue Summe-Zeile
    With .Rows(.Rows.Count)
      .Font.Bold = True
      .Cells(1).Value = "Summe"
      .Cells(3).NumberFormat = "#,##0.00 $"
      .Cells(3).Formula = "=SUM(R[-1]C:R[-" & rng.Rows.Count - 1 & "]C)"
    End With
    
    'Datum- und Wert-Spalte formatieren
    .Columns(1).NumberFormat = "dd.mm.yyyy hh:mm"
    .Columns(3).NumberFormat = "#,##0.00 $"
    
    Call .Columns(2).AutoFit
    
    'Rahmen setzen
    .Borders.LineStyle = XlLineStyle.xlContinuous
    .Borders.Weight = XlBorderWeight.xlThin
    
  End With
  
  ActiveWindow.DisplayGridlines = False
  
  Call rng.Resize(RowSize:=4).Insert(xlShiftDown)
  Call rng.Cells(1, 1).Select
  
End Sub

Private Function WorksheetExists(Name As String, Optional ByVal Workbook As Excel.Workbook) As Boolean
  If Workbook Is Nothing Then Set Workbook = ActiveWorkbook
  On Error Resume Next
  WorksheetExists = Not (Workbook.Worksheets(Name) Is Nothing)
End Function

 


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
22.05.2014 10:05:48 HR
NotSolved
22.05.2014 15:30:55 Amicro2000
NotSolved
22.05.2014 19:19:51 Gast64552
NotSolved
22.05.2014 19:25:42 Gast19909
NotSolved
Rot Komplett mir überarbeiteter GAForm
22.05.2014 20:50:25 Gast60763
*****
Solved
23.05.2014 13:10:06 HR
NotSolved
23.05.2014 13:31:25 Gast24605
*****
Solved
23.05.2014 13:10:06 HR
NotSolved
23.05.2014 16:50:19 HR
NotSolved
23.05.2014 17:15:11 Gast66050
Solved