• 매크로는 통합 문서에 Master라는 이름의 시트를 추가하고이 워크 시트의 통합 문서에있는 모든 시트의 셀을 복사합니다.

  • 첫 번째 매크로는 일반 복사를 수행하고 두 번째 매크로는 값을 복사합니다.

  • 매크로의 하위 기능은 아래 기능을 사용하며, 기능 없이는 매크로가 작동하지 않습니다.

이 sh.Rows ( “1 : 4”). Copy를 사용하여 하나 이상의 행을 복사합니다.

Sub Test4()

Dim sh As Worksheet

Dim DestSh As Worksheet

Dim Last As Long

If SheetExists("Master") = True Then

MsgBox "The sheet Master already exist"

Exit Sub

End If

Application.ScreenUpdating = False

Set DestSh = Worksheets.Add

DestSh.Name = "Master"

For Each sh In ThisWorkbook.Worksheets

If sh.Name <> DestSh.Name Then

If sh.UsedRange.Count > 1 Then

Last = LastRow(DestSh)

sh.Rows("1").Copy DestSh.Cells(Last + 1, 1)

End If

End If

Next

Application.ScreenUpdating = True

End Sub

Sub Test4_Values()

Dim sh As Worksheet

Dim DestSh As Worksheet

Dim Last As Long

If SheetExists("Master") = True Then

MsgBox "The sheet Master already exist"

Exit Sub

End If

Application.ScreenUpdating = False

Set DestSh = Worksheets.Add

DestSh.Name = "Master"

For Each sh In ThisWorkbook.Worksheets

If sh.Name <> DestSh.Name Then

If sh.UsedRange.Count > 1 Then

Last = LastRow(DestSh)

With sh.Rows("1")

DestSh.Cells(Last + 1, 1).Resize(.Rows.Count, _

.Columns.Count).Value = .Value

End With

End If

End If

Next

Application.ScreenUpdating = True

End Sub

Function LastRow(sh As Worksheet)

On Error Resume Next

LastRow = sh.Cells.Find(What:="*", _

After:=sh.Range("A1"), _

Lookat:=xlPart, _

LookIn:=xlFormulas, _

SearchOrder:=xlByRows, _

SearchDirection:=xlPrevious, _

MatchCase:=False).Row

On Error GoTo 0

End Function

Function Lastcol(sh As Worksheet)

On Error Resume Next

Lastcol = sh.Cells.Find(What:="*", _

After:=sh.Range("A1"), _

Lookat:=xlPart, _

LookIn:=xlFormulas, _

SearchOrder:=xlByColumns, _

SearchDirection:=xlPrevious, _

MatchCase:=False).Column

On Error GoTo 0

End Function

Function SheetExists(SName As String, _

Optional ByVal WB As Workbook) As Boolean

On Error Resume Next

If WB Is Nothing Then Set WB = ThisWorkbook

SheetExists = CBool(Len(Sheets(SName).Name))

End Function