- Makroen tilføjer et ark med navnet Master til din projektmappe og kopierer cellerne fra hvert ark i din projektmappe i dette regneark.
- Den første makro kopierer en normal kopi, og den anden makro kopierer værdierne.
- Makroens subs bruger funktionerne herunder, makroerne fungerer ikke uden funktionerne.
Sub CopyFromRow () Dim sh As Worksheet Dim DestSh As Worksheet Dim shLast As Long Dim Last As Long If SheetExists ("Master") = True Then MsgBox "Sheet Master exist exist" Exit Sub End If Application.ScreenUpdating = False Set DestSh = Worksheets.Add DestSh.Name = "Master" for hver sh i ThisWorkbook.Worksheets If sh.Name DestSh.Name Then If sh.UsedRange.Count> 1 Then Last = LastRow (DestSh) shLast = LastRow (sh) sh.Range ( sh.Rows (3), sh.Rows (shLast)). Copy DestSh.Cells (Last + 1, 1) End If End If Next Application.ScreenUpdating = True End Sub Sub CopyFromRowValues () Dim sh As Worksheet Dim DestSh As Worksheet Dim shLast As Long Dim Last As Long If SheetExists ("Master") = True Så er MsgBox "Sheet Master allerede" Exit Sub End If Application.ScreenUpdating = False Set DestSh = Worksheets.Add DestSh.Name = "Master" For hver sh I ThisWorkbook.Worksheets If sh.Name DestSh.Name Then If sh.UsedRange.Count> 1 Then Last = LastRow (DestSh) shLast = LastRow (sh) With sh.Range (sh.Rows (3), sh.Rows (shLast)) DestSh.Cells (Last + 1, 1) .Resize (.Rows.Count, _ .Columns.Count) .Value = .Value End With End If End If Next If Next Application.ScreenUpdating = True End Sub Funktion LastRow (sh Som regneark) Ved fejl Genoptag Næste LastRow = sh.Cells.Find (Hvad: = "*", _ Efter: = sh.Range ("A1"), _ Lookat: = xlPart, _ LookIn: = xlFormulas , _ SearchOrder: = xlByRows, _ SearchDirection: = xlPrevious, _ MatchCase: = False) .Række ved fejl Gå til 0 Afslut funktion Funktion Lastcol (sh Som regneark) Ved fejl Genoptag Næste Lastcol = sh.Cells.Find (Hvad: = " *", _ After: = sh.Range (" A1 "), _ Lookat: = xlPart, _ LookIn: = xlFormulas, _ SearchOrder: = xlByColumns, _ SearchDirection: = xlPrevious, _ MatchCase: = False) .Column On Error GoTo 0 Afslut funktion Funktion SheetExists (SName As String, _ Valgfri ByVal WB som arbejdsmappe) Som boolsk On Error Resume Next Hvis WB ikke er noget Så indstil WB = ThisWorkbook SheetExists = CBool (Len (Sheets (SName) .Name)) Slut funktion