Excel 2010에서 워크시트 전체를 새 워크시트에 복사
하나의 워크북에 전체 워크시트를 복사하여 다른 워크북에 붙여넣는 것과 유사한 질문을 발견했지만, 워크북 전체를 복사하여 같은 워크북에 새 워크북에 붙여넣는 것에 관심이 있습니다.
2003.xls 파일을 2010.xlsm으로 변환하고 있는데, 워크시트 간에 복사 및 붙여넣기에 사용된 이전 방법이 올바른 행 높이로 붙여넣기 되지 않습니다.초기 회피책은 각 행을 루프하여 복사 중인 워크시트에서 행 높이를 가져온 다음 루프하여 붙여넣는 워크시트에 행 높이에 대한 값을 삽입하는 것이었습니다.그러나 이 접근법의 문제는 시트에 행 번호를 변경하는 새로운 행을 생성하는 버튼이 포함되어 있고 시트의 형식은 모든 행이 하나의 너비일 수 없다는 것입니다.
워크시트 전체를 복사하여 붙여넣기만 하면 됩니다.2003 버전의 코드를 다음에 나타냅니다.
ThisWorkbook.Worksheets("Master").Cells.Copy
newWorksheet.Paste
.xlsm으로 변환한 것이 원인이 되어 파손된 것이 놀랍습니다.어떤 제안이나 아이디어라도 좋습니다.
마지막 시트로 넣으려면 아래와 같이 정확한 복사본을 실행하는 것이 더 쉽습니다.
Sub Test()
Dim ws1 As Worksheet
Set ws1 = ThisWorkbook.Worksheets("Master")
ws1.Copy ThisWorkbook.Sheets(Sheets.Count)
End Sub
ThisWorkbook.Worksheets("Master").Sheet1.Cells.Copy _
Destination:=newWorksheet.Cells
위는 셀을 복사합니다.정말 시트 전체를 복제하고 싶다면 @brettdj의 답변으로 하겠습니다.
' Assume that the code name the worksheet is Sheet1
' Copy the sheet using code name and put in the end.
' Note: Using the code name lets the user rename the worksheet without breaking the VBA code
Sheet1.Copy After:=Sheets(Sheets.Count)
' Rename the copied sheet keeping the same name and appending a string " copied"
ActiveSheet.Name = Sheet1.Name & " copied"
저는 @brettdj의 코드가 너무 좋았는데, 복사 편집용 코드를 추가하면 원래 시트에 오버랩이 되어 버립니다.그의 대답을 수정해서 더 많은 코드가ws1원본이 아닌 새 시트에 영향을 줍니다.
Sub Test()
Dim ws1 as Worksheet
ThisWorkbook.Worksheets("Master").Copy
Set ws1 = ThisWorkbook.Worksheets("Master (2)")
End Sub
'Make the excel file that runs the software the active workbook
ThisWorkbook.Activate
'The first sheet used as a temporary place to hold the data
ThisWorkbook.Worksheets(1).Cells.Copy
'Create a new Excel workbook
Dim NewCaseFile As Workbook
Dim strFileName As String
Set NewCaseFile = Workbooks.Add
With NewCaseFile
Sheets(1).Select
Cells(1, 1).Select
End With
ActiveSheet.Paste
저처럼 기본 가격표 수, 요약 및 기밀 데이터로 가득 찬 숨겨진 '보호된' 워크시트가 다수 포함된 견적 워크북을 가지고 있지만 적절한 가격으로 제공하려면 가시적인 워크시트를 추가로 작성해야 할 경우,숨겨진 보호된 "마스터"를 기반으로 해당 가시 워크시트를 생성하는 상기 응답의 변형이 있습니다.@/jean-fran%c3%a7ois-corbett 및 @thanos-a가 제공하는 코드를 아래와 같이 간단한 VBA와 조합하여 사용하고 있습니다.
Sub sbInsertWorksheetAfter()
'This adds a new visible worksheet after the last visible worksheet
ThisWorkbook.Sheets.Add After:=Worksheets(Worksheets.Count)
'This copies the content of the HIDDEN "Master" worksheet to the new VISIBLE ActiveSheet just created
ThisWorkbook.Sheets("Master").Cells.Copy _
Destination:=ActiveSheet.Cells
'This gives the the new ActiveSheet a default name
With ActiveSheet
.Name = Sheet12.Name & " copied"
End With
'This changes the name of the ActiveSheet to the user's preference
Dim sheetname As String
With ActiveSheet
sheetname = InputBox("Enter name of this Worksheet")
.Name = sheetname
End With
종료 서브
언급URL : https://stackoverflow.com/questions/8439657/copy-an-entire-worksheet-to-a-new-worksheet-in-excel-2010
'programing' 카테고리의 다른 글
| 특정 단어를 사용하여 엑셀의 한 줄을 복사하고 다른 엑셀 시트에 붙여넣는 방법은 무엇입니까? (0) | 2023.06.15 |
|---|---|
| 로컬 스토리지에서 Vuex 상태가 업데이트되지 않음 (0) | 2023.06.15 |
| 서버 실행에 실패했습니다(HRESULT: 0x80080005(CO_E_SERVER_EXEC_).실패) (0) | 2023.04.21 |
| Microsoft Azure 문서DB vs Azure 테이블 스토리지 (0) | 2023.04.21 |
| 긴 n = 2000*2000*2000; 오버플로우인 이유는 무엇입니까? (0) | 2023.04.21 |