- ©«¤l
- 1
- ¥DÃD
- 1
- ºëµØ
- 0
- ¿n¤À
- 2
- ÂI¦W
- 0
- §@·~¨t²Î
- windows 2010
- ³nÅ骩¥»
- excel 2016
- ¾\ŪÅv
- 10
- µù¥U®É¶¡
- 2017-12-11
- ³Ì«áµn¿ý
- 2018-8-29
|
[µo°Ý] ½Ð°ÝVBA¦p¦ó°j°é¿ï¨ú¤w¿z¿ïªº¸ê®Æ½Æ»s¨ì·s¤u§@ªí¤Wªº¯S©w½d³ò
¦pÃD, §Ú·Q¨Ï¥ÎVBA¥h°j°é¿ï¨ú¤w¿z¿ïªº¸ê®Æ½Æ»s¨ì·s¤u§@ªí¤Wªº¯S©w½d³ò¤Î¦Û°Ê¶}·s¤@¦æ¡C
§Ú¹Á¸Õ¿ý»s¤F¥¨¶°¤Îקï¤F¤Ö³\,¦ý¤£¦¨¥\¡C
VBAªº ¨BÆJ:
1.«ö¤U¦bSHEET ¡§VBA¡¨ ¤Wªº In out record 7 days«ö§á
2.·í«ö¤U¨î«á,·|¿ï¾ÜSHEET ¡§AT¡¨
3.¦bSHEET¡¨AT¡¨¤W, ¥ÑA6©Ô¨ìAD6, ¤§«á«ö¿z¿ï
4.¤§«á¦bF6¶i¦æ¤é´Á¿z¿ï,
5.§âSHEET ¡§In out record¡¨ ½Æ»s¤@±i·sSHEET ¥s ¡§In out record 2¡¨
6.§â¡¨In out record 2¡¨½Æ»s¤@±i·sSHEET¥s¡¨In out record_AT¡¨
7.§âè¤~¦bSHEET ¡§AT¡¨¤W¿z¿ï±o¥Xªº¸ê®Æ½Æ»s
8.¦bSHEET ¡¨In out record_AT¡¨ set C12 ªºVALUE ¬OAT
9.¦bSHEET¡¨ In out record_AT¡¨ ªºB17 ¶K¤Wè¤~©Ò½Æ»sªº¸ê®Æ,¨C½Æ»s¤@¦¸,¶}·s¤@¦æ, ¦b·s¤@¦æ¤WÄ~Äò½Æ»s¤Î¤£°÷¦ì¦Û°ÊINSERT·s¤@¦æ
«½Æ¨BÆJ4¦Ü8, °µ7¦¸(¤µ¤é«e3¤Ñ¨ì¤µ¤é«á3¤Ñ,¦@7¤Ñ)
§Ú²{¦b°µ¨ì¤F1¦Ü8,¦ý¨BÆJ9°µ¤F¤@¦¸ÁÙ¥i¥H,¤§«á¦A½Æ»s´N·|Âл\¤§«eªº¸ê®Æ
½Ð°Ý¦p¦óקï? ³Â·Ð«ü¾É¡A·PÁ¡C
Code:- Private Sub CommandButton17_Click()
- Set copysheet = ThisWorkbook.Sheets("In out record")
- copysheet.Activate
- copysheet.Range("A1:O49").Select
- Selection.Copy
- Sheets.Add After:=Sheets(Sheets.Count)
- Selection.PasteSpecial Paste:=xlPasteColumnWidths, Operation:=xlNone, _
- SkipBlanks:=False, Transpose:=False
- ActiveSheet.Paste
- ActiveSheet.Name = "In out record 2"
- Set copysheet2 = ThisWorkbook.Sheets("In out record 2")
- copysheet2.Copy After:=Sheets("In out record 2")
- Set ATworksheet = Sheets(Sheets("In out record 2").Index + 1)
- ATworksheet.Name = "In out record_AT"
- Set wSheetStart = ThisWorkbook.Sheets("AT")
- wSheetStart.Activate
- wSheetStart.AutoFilterMode = False
- ActiveSheet.Range("A6:AC6").AutoFilter Field:=6, Criteria1:=">=" & DateSerial(Year(Now - 3), Month(Now - 3), Day(Now - 3)), Operator:=xlAnd, Criteria2:="<=" & DateSerial(Year(Now - 3), Month(Now - 3), Day(Now - 3))
- If ActiveSheet.AutoFilter.Range.Columns(1).SpecialCells(xlCellTypeVisible).Count > 1 Then
- Worksheets("AT").Range("B7").Select
- Worksheets("AT").Range("B7:N7").Select
- Worksheets("AT").Range(Selection, Selection.End(xlDown)).Select
- Selection.Copy
- ATworksheet.Activate
- ATworksheet.Range("B17").PasteSpecial
-
- ATworksheet.Range("C12").Value = "AT"
-
- Set btn = ActiveSheet.Buttons.Add(477, 177, 40, 40)
- With btn
- .OnAction = "btnS"
- .Caption = "Save As"
- .Name = "Save As"
- Application.ScreenUpdating = True
- End With
-
- ATworksheet.Range("B21").Select
-
- wSheetStart.Activate
- ActiveSheet.Range("A6:AC6").AutoFilter Field:=6, Criteria1:=">=" & DateSerial(Year(Now - 2), Month(Now - 2), Day(Now - 2)), Operator:=xlAnd, Criteria2:="<=" & DateSerial(Year(Now - 2), Month(Now - 2), Day(Now - 2))
- If ActiveSheet.AutoFilter.Range.Columns(1).SpecialCells(xlCellTypeVisible).Count > 1 Then
- Worksheets("AT").Range("B7").Select
- Worksheets("AT").Range("B7:N7").Select
- Worksheets("AT").Range(Selection, Selection.End(xlDown)).Select
- Selection.Copy
- ATworksheet.Activate
- ATworksheet.Range("B17").End(xlUp).Offset(1).PasteSpecial
-
- wSheetStart.Activate
- ActiveSheet.Range("A6:AC6").AutoFilter Field:=6, Criteria1:=">=" & DateSerial(Year(Now - 1), Month(Now - 1), Day(Now - 1)), Operator:=xlAnd, Criteria2:="<=" & DateSerial(Year(Now - 1), Month(Now - 1), Day(Now - 1))
- If ActiveSheet.AutoFilter.Range.Columns(1).SpecialCells(xlCellTypeVisible).Count > 1 Then
- Worksheets("AT").Range("B7").Select
- Worksheets("AT").Range("B7:N7").Select
- Worksheets("AT").Range(Selection, Selection.End(xlDown)).Select
- Selection.Copy
- ATworksheet.Activate
- ATworksheet.Range("B17").End(xlUp).Offset(3).PasteSpecial
-
- wSheetStart.Activate
- ActiveSheet.Range("A6:AC6").AutoFilter Field:=6, Criteria1:=">=" & DateSerial(Year(Now), Month(Now), Day(Now)), Operator:=xlAnd, Criteria2:="<=" & DateSerial(Year(Now), Month(Now), Day(Now))
- If ActiveSheet.AutoFilter.Range.Columns(1).SpecialCells(xlCellTypeVisible).Count > 1 Then
- Worksheets("AT").Range("B7").Select
-
- Worksheets("AT").Range("B7:N7").Select
- Worksheets("AT").Range(Selection, Selection.End(xlDown)).Select
- Selection.Copy
- ATworksheet.Activate
- ATworksheet.Range("B17").End(xlUp).Offset(5).PasteSpecial
-
- wSheetStart.Activate
- ActiveSheet.Range("A6:AC6").AutoFilter Field:=6, Criteria1:=">=" & DateSerial(Year(Now + 1), Month(Now + 1), Day(Now + 1)), Operator:=xlAnd, Criteria2:="<=" & DateSerial(Year(Now + 1), Month(Now + 1), Day(Now + 1))
- If ActiveSheet.AutoFilter.Range.Columns(1).SpecialCells(xlCellTypeVisible).Count > 1 Then
- Worksheets("AT").Range("B7").Select
- Worksheets("AT").Range("B7:N7").Select
- Worksheets("AT").Range(Selection, Selection.End(xlDown)).Select
- Selection.Copy
- ATworksheet.Activate
- ATworksheet.Range("B17").End(xlUp).Offset(7).PasteSpecial
-
- wSheetStart.Activate
- ActiveSheet.Range("A6:AC6").AutoFilter Field:=6, Criteria1:=">=" & DateSerial(Year(Now + 2), Month(Now + 2), Day(Now + 2)), Operator:=xlAnd, Criteria2:="<=" & DateSerial(Year(Now + 2), Month(Now + 2), Day(Now + 2))
- If ActiveSheet.AutoFilter.Range.Columns(1).SpecialCells(xlCellTypeVisible).Count > 1 Then
- Worksheets("AT").Range("B7").Select
- Worksheets("AT").Range("B7:N7").Select
- Worksheets("AT").Range(Selection, Selection.End(xlDown)).Select
- Selection.Copy
- ATworksheet.Activate
- ATworksheet.Range("B17").End(xlUp).Offset(9).PasteSpecial
-
- wSheetStart.Activate
- ActiveSheet.Range("A6:AC6").AutoFilter Field:=6, Criteria1:=">=" & DateSerial(Year(Now + 3), Month(Now + 3), Day(Now + 3)), Operator:=xlAnd, Criteria2:="<=" & DateSerial(Year(Now + 3), Month(Now + 3), Day(Now + 3))
- If ActiveSheet.AutoFilter.Range.Columns(1).SpecialCells(xlCellTypeVisible).Count > 1 Then
- Worksheets("AT").Range("B7").Select
- Worksheets("AT").Range("B7:N7").Select
- Worksheets("AT").Range(Selection, Selection.End(xlDown)).Select
- Selection.Copy
- ATworksheet.Activate
- ATworksheet.Range("B17").End(xlUp).Offset(11).PasteSpecial
-
- End If
- End If
- End If
- End If
- End If
- End If
- End If
- End Sub
-
½Æ»s¥N½X |
|