Sub changeFile()
For i = 8 To ActiveWorkbook.Sheets.Count
Worksheets(i).Select
changeSheet (i)
Next i
'makeIndex
deleteHeader
End SubSub makeIndex()
Worksheets(2).Select
For i = ActiveWorkbook.Sheets.Count To 4 Step -1
Rows("2:2").Select
Selection.Copy
Selection.Insert Shift:=xlDown
Range("F3").Activate
ActiveCell.FormulaR1C1 = Worksheets(i).Name
Next i
End SubSub changeSheet(idx As Integer)
'레이아웃 편집
Rows("1:2").Select
With Selection
.MergeCells = False
End With
Columns("A:A").Select
Range("A2").Activate
Selection.Delete Shift:=xlToLeft
Columns("B:C").Select
Selection.Insert Shift:=xlToRight
Columns("F:F").Select
Range("F3").Activate
Selection.Insert Shift:=xlToRight
Columns("I:J").Select
Range("I3").Activate
Selection.Insert Shift:=xlToRight
Columns("M:Q").Select
Selection.Insert Shift:=xlToRight
Columns("M:Q").Select
Selection.ColumnWidth = 2.3
Range("B3").Select
'속성정보 편집
Columns("G:G").Select
Range("G5").Activate
Selection.Replace What:="X", Replacement:="C", LookAt:=xlPart, _
SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
ReplaceFormat:=False
Selection.Replace What:="9", Replacement:="N", LookAt:=xlPart, _
SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
ReplaceFormat:=False
Columns("B:C").Select
Selection.ColumnWidth = 3
Columns("E:E").Select
Selection.Copy
Columns("D:D").Select
Selection.Insert Shift:=xlToRight
Columns("F:F").Select
Selection.Delete Shift:=xlToLeft
Columns("A:A").Select
Selection.ColumnWidth = 3
Columns("B:C").Select
Selection.ColumnWidth = 6
Columns("D:E").Select
Selection.ColumnWidth = 20
Columns("F:K").Select
Selection.ColumnWidth = 3
Columns("L:L").Select
Selection.ColumnWidth = 35
Columns("R:R").Select
Selection.ColumnWidth = 15
'비고필드 자동줄바꿈
Columns("R:R").Select
Range("R2").Activate
With Selection
.VerticalAlignment = xlCenter
.WrapText = True
.Orientation = 0
.AddIndent = False
.ShrinkToFit = False
.ReadingOrder = xlContext
End With
'첫번째시트에서 타이틀 카피
Worksheets(1).Select
Rows("1:7").Select
Range("A7").Activate
Selection.Copy
Worksheets(idx).Select
Rows("1:1").Select
Selection.Insert Shift:=xlDown
'타이틀 편집
Range("E2:H2").Activate
ActiveCell.FormulaR1C1 = "재무"
Range("E3:H3").Activate
ActiveCell.FormulaR1C1 = ""
Range("A9").Select
Selection.Copy
Range("A9").Select
Range("E4:H4").Select
ActiveSheet.Paste
Range("L4").Select
ActiveCell.FormulaR1C1 = ""
Range("R2").Select
ActiveCell.FormulaR1C1 = "재무"
Range("R3").Select
ActiveCell.FormulaR1C1 = ""
Range("R4").Select
ActiveCell.FormulaR1C1 = Worksheets(idx).Name
Rows("8:10").Select
Selection.Delete Shift:=xlToUp
Columns("A:A").Select
Range("A1").Activate
With Selection.Font
.Size = 10
.Strikethrough = False
.Superscript = False
.Subscript = False
.OutlineFont = False
.Shadow = False
.Underline = xlUnderlineStyleNone
End With
ActiveWindow.Zoom = 85
End SubSub deleteHeader()
For i = 8 To ActiveWorkbook.Sheets.Count
Worksheets(i).Select
Rows("8:21").Select
Selection.Delete Shift:=xlToUp
Range("A8").Select
ActiveCell.FormulaR1C1 = "1"
Next i
End Sub
Sub copyValue()'값만 copyRange("A600").ActivateCells.SelectSelection.CopyRange("A1").SelectSelection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _:=False, Transpose:=FalseRange("A1").SelectApplication.CutCopyMode = FalseRange("s1").SelectEnd Sub
Sub copyValueSheet()For i = 8 To ActiveWorkbook.Sheets.CountWorksheets(i).SelectcopyValueNext iEnd Sub
Sub all()For i = 8 To ActiveWorkbook.Sheets.CountWorksheets(i).SelectcopyValueeditFormNext iEnd Sub
Sub editSheet()For i = 8 To ActiveWorkbook.Sheets.CountWorksheets(i).SelecteditFormNext iEnd Sub
Sub editForm()Columns("B:B").SelectSelection.Delete Shift:=xlToLeftColumns("F:K").SelectSelection.Delete Shift:=xlToLeftColumns("H:H").SelectSelection.Delete Shift:=xlToLeftColumns("I:I").SelectSelection.Delete Shift:=xlToLeftColumns("J:J").SelectSelection.Delete Shift:=xlToLeftColumns("s:S").SelectSelection.Delete Shift:=xlToLeftrowNumberingEnd Sub
Sub rowNumbering()'마지막 row까지For i = 8 To Range("A8").End(xlDown).RowRange("A" & i).ActivateActiveCell.FormulaR1C1 = i - 7Next iEnd Sub
'formula xls 에서 문서ID, SEQ 와 MSGID, SEQ 를 가져와 LIST 로 만드는 함수'파일다이얼로그창에서 적용할 파일을 선택해서 동작시킨다.Sub xlsSeq()Dim Files As VariantDim fileX As VariantDim wb As WorkbookDim xlsSheet As WorksheetDim listSheet As Worksheet
Set listSheet = Worksheets("ID_SEQ_LIST_B3")Files = Application.GetOpenFilename(filefilter:="total Files(*.*),*.*", Title:="파일선택", MultiSelect:=True)For Each fileX In FilesSet wb = Workbooks.Open(fileX)For m = 8 To wb.Sheets.CountSet xlsSheet = wb.Worksheets(m)Call getXlsSEQ(xlsSheet, listSheet)Next m'파일 저장후 closewb.Savewb.CloseNext fileXEnd Sub
Private Sub getXlsSEQ(xlsWs As Worksheet, listWs As Worksheet)
Dim xlsID As StringDim msgID As StringDim listLastRow, xlsLastRow As IntegerxlsLastRow = xlsWs.Range("A65535").End(xlUp).RowIf Not (IsError(xlsWs.Range("P2").Value)) ThenxlsID = xlsWs.Range("P2").ValuemsgID = xlsWs.Range("P4").Value'마지막 row까지For i = 8 To xlsLastRowlistLastRow = listWs.Range("A65535").End(xlUp).Row + 1listWs.Cells(listLastRow, 1).Value = msgIDlistWs.Cells(listLastRow, 2).Value = xlsWs.Range("A" & i).ValuelistWs.Cells(listLastRow, 3).Value = xlsIDlistWs.Cells(listLastRow, 4).Value = xlsWs.Range("B" & i).ValueNext iEnd IfEnd Sub
Sub editFormatIoCls()Dim Files As VariantDim fileX As VariantDim wb As WorkbookFiles = Application.GetOpenFilename(filefilter:="total Files(*.*),*.*", Title:="파일선택", MultiSelect:=True)For Each fileX In FilesSet wb = Workbooks.Open(fileX)For m = 8 To wb.Sheets.Countwb.Worksheets(m).Selectwb.Worksheets(m).Columns("M:M").SelectSelection.Copy'copy 한 columns 를 붙여넣기wb.Worksheets(m).Columns("T:T").SelectSelection.Insert Shift:=xlToRightwb.Worksheets(m).Columns("M:M").SelectSelection.Delete Shift:=xlToLeftwb.Worksheets(m).Columns("Q:Q").SelectSelection.Insert Shift:=xlToRightNext mwb.Savewb.CloseNext fileXEnd Sub
Sub addFormula()Dim Files As VariantDim fileX As VariantDim wb As WorkbookFiles = Application.GetOpenFilename(filefilter:="total Files(*.*),*.*", Title:="파일선택", MultiSelect:=True)For Each fileX In FilesSet wb = Workbooks.Open(fileX)For m = 8 To wb.Worksheets.Countwb.Worksheets(m).Selectwb.Worksheets(m).Range("P2").Formula = "=VLOOKUP(P4, [000.0.macro.xls]ID_SEQ_LIST_B3!$E:$F, 2, FALSE)"Call addFormulaXlsSEQ(wb.Worksheets(m))Next mwb.Savewb.CloseNext fileXEnd Sub
Sub addFormulaXlsSEQ(xlsWs As Worksheet)Dim xlsLastRow As IntegerIf Not (IsError(xlsWs.Range("P2").Value)) ThenWith xlsWsxlsLastRow = Range("A65535").End(xlUp).RowColumns("E:E").SelectSelection.CopySelection.Insert Shift:=xlToRightColumns("E:E").SelectSelection.Replace What:="_", Replacement:="", LookAt:=xlPart, _SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _ReplaceFormat:=FalseRange("B8").SelectApplication.CutCopyMode = False'셀에 수식넣기ActiveCell.FormulaR1C1 = "=VLOOKUP(RC[3],C30:C31, 2, FALSE)"'Range 에 수식을 AutoFillIf xlsLastRow > 8 ThenSelection.AutoFill Destination:=Range("B8:B" & xlsLastRow)End IfRange("B8:B" & xlsLastRow).SelectSelection.CopyRange("B8").Select'copy 한 selection 을 선택붙여넣기로 값만 넣기Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _:=False, Transpose:=FalseColumns("B:B").Select'Find 로 문자열 #N/A 를 찾아 "" 로 replace 하기Selection.Replace What:="#N/A", Replacement:="", LookAt:=xlPart, _SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _ReplaceFormat:=FalseColumns("E:E").SelectSelection.Delete Shift:=xlToLeftEnd WithElsexlsWs.Range("A8").SelectEnd IfEnd Sub
'시트명 (msgid) 변경Sub changeSheetsName()Dim Files As VariantDim fileX As VariantDim wb As WorkbookFiles = Application.GetOpenFilename(filefilter:="total Files(*.*),*.*", Title:="파일선택", MultiSelect:=True)For Each fileX In FilesSet wb = Workbooks.Open(fileX)Call changeSheetName(wb)Call changeMsgId(wb)wb.Savewb.CloseNext fileX
End Sub
Private Sub changeSheetName(wb As Workbook)For i = 1 To wb.Worksheets.CountIf i < 8 ThenIf i = 1 Or i = 6 Or i = 7 ThenWith wb.Worksheets(i).SelectColumns("F:F").SelectSelection.Replace What:="B30", Replacement:="B3", LookAt:=xlPart, _SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _ReplaceFormat:=FalseEnd WithEnd IfElsewb.Worksheets(i).Name = Left(wb.Worksheets(i).Name, 2) & Right(wb.Worksheets(i).Name, 4)End IfNext iEnd Sub
Private Sub changeMsgId(wb As Workbook)For i = 8 To wb.Worksheets.CountWith wb.Worksheets(i).Select'Formula 와 FormulaR1C1 의 차이점. Formula 로 수식을 넣을 때, 따옴표처리는 Chr(34)Range("P4").Formula = "=REPLACE(CELL(" & Chr(34) & "filename" & Chr(34) & ",A1),1,FIND(" & Chr(34) & "]" & Chr(34) & ",CELL(" & Chr(34) & "filename" & Chr(34) & ",A1))," & Chr(34) & "" & Chr(34) & ")"End WithNext iEnd Sub
Sheets("B200003").SelectSheets("B200003").Copy After:=Sheets(ActiveWorkbook.Sheets.Count)ActiveSheet.Name = "B200004"
Sheets("B200003").Name = "ABC"
'excel' 카테고리의 다른 글
[함수]문자열자르기 - SEARCH (0) | 2008.11.11 |
---|---|
[함수]중복된 목록에서 데이터 불러오기 (0) | 2008.10.02 |
[함수]파일 및 시트명 (0) | 2008.09.30 |
[함수]엑셀함수 (0) | 2008.09.30 |
[함수]indirect - 문자열을 참조로 사용할 때 (0) | 2008.09.25 |