- 帖子
- 192
- 主題
- 15
- 精華
- 0
- 積分
- 194
- 點名
- 0
- 作業系統
- windows
- 軟體版本
- office2010
- 閱讀權限
- 20
- 性別
- 女
- 註冊時間
- 2016-9-22
- 最後登錄
- 2020-8-28
 
|
本帖最後由 starbox520 於 2017-1-4 10:28 編輯
此程式可在這裡輸入日期(紅線圈起部分)
會找網段上資料,依我輸入的日期之間的所有的資料
(中間有一些公式做計算)
像上圖就是會去找5月1號-5月31號的資料
現在想新增一個botten不需輸入日期
按下會直接跑昨日的資料,還請指導一下,還有這隻程式有時候會跑到1年的資料
相對的就會跑超久…最久一次跑了快2天= =",程式碼部分有辦法優化嗎- Sub Sumbit()
- clean_rawdata
- Sheets("Act_UTZ").Select
- Range("D4").Value = "手動"
- Dim Src As String
-
-
- Application.DisplayAlerts = False
-
-
- Src = ThisWorkbook.Name
-
- start_year = Left(Worksheets("Main").Cells(2, 2), 4)
- end_year = Left(Worksheets("Main").Cells(2, 4), 4)
-
- start_month = Mid(Worksheets("Main").Cells(2, 2), 5, 2)
- end_month = Mid(Worksheets("Main").Cells(2, 4), 5, 2)
-
- start_day = Right(Worksheets("Main").Cells(2, 2), 2)
- end_day = Right(Worksheets("Main").Cells(2, 4), 2)
-
- start_date = Right(Worksheets("Main").Cells(2, 2), 4)
- end_date = Right(Worksheets("Main").Cells(2, 4), 4)
-
-
- ''''plan_period為所要下載之PC Plan版本日期
-
-
- If Val(end_month) > Val(start_month) Or Val(end_year) > Val(start_year) Then
-
- If start_month = "01" Or start_month = "03" Or start_month = "05" Or start_month = "07" Or start_month = "08" Or start_month = "10" Or start_month = "12" Then
- m1 = 31
- End If
- If start_month = "02" Then
- m1 = 29
- End If
- If start_month = "04" Or start_month = "06" Or start_month = "09" Or start_month = "11" Then
- m1 = 30
- End If
-
- plan_period = m1 - Val(start_day) + Val(end_day)
-
- End If
-
- If Val(end_month) = Val(start_month) Then
-
- If start_month = "01" Or start_month = "03" Or start_month = "05" Or start_month = "07" Or start_month = "08" Or start_month = "10" Or start_month = "12" Then
- m1 = 31
- End If
- If start_month = "02" Then
- m1 = 29
- End If
- If start_month = "04" Or start_month = "06" Or start_month = "09" Or start_month = "11" Then
- m1 = 30
- End If
-
- plan_period = Val(end_day) - Val(start_day)
-
- End If
-
-
- ' Worksheets("Raw_Data_1").Select
-
- 'Cells.Select
- ' Selection.EntireColumn.Hidden = False
- ' Worksheets("Raw_Data_1").AutoFilterMode = False
-
-
-
- For I = 0 To plan_period
-
- If Val(start_day) + I > m1 Then
-
- If Val(start_month) <= 8 Then
-
- month_var = "0" & Val(start_month) + 1
-
- ElseIf Val(start_month) >= 12 Then
-
- month_var = "0" & Val(start_month) + 1 - 12
-
- ElseIf Val(start_month) >= 9 Then
-
- month_var = Val(start_month) + 1
-
- End If
-
- If Val(start_day) + I - m1 <= 9 Then
-
- day_var = "0" & Val(start_day) + I - m1
-
- ElseIf Val(start_day) + I - m1 >= 10 Then
-
- day_var = Val(start_day) + I - m1
-
- End If
-
- plan_date = end_year & month_var & day_var
-
- End If
-
- '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
-
- If Val(start_day) + I <= m1 Then
-
- If Val(start_day) + I <= 9 Then
-
- day_var = "0" & Val(start_day) + I
-
- ElseIf Val(start_day) + I >= 10 Then
-
- day_var = Val(start_day) + I
-
- End If
-
- plan_date = start_year & start_month & day_var
-
- End If
-
-
- '在""可輸入網址
- Importfilepath = ""
-
- Set oldbook = Workbooks.Open(Importfilepath)
-
- 'Application.AutomationSecurity = secAutomation
-
-
-
- '-------------------------------------------------------------------------------------------------------------------
-
- Columns("A:X").Select
- Selection.Copy
- Windows(Src).Activate
- Sheets("output").Select
- Range("A1").Select
- Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
- :=False, Transpose:=False
-
- Range("X2").Select
- Application.CutCopyMode = False
- ActiveCell.FormulaR1C1 = "=RC[-15]&RC[-20]"
- Range("X2").Select
- With Selection.Interior
- .Pattern = xlSolid
- .PatternColorIndex = xlAutomatic
- .ThemeColor = xlThemeColorLight2
- .TintAndShade = 0.799981688894314
- .PatternTintAndShade = 0
- End With
- Range("X1").Select
- ActiveCell.FormulaR1C1 = "$"
-
-
- '下拉
- Dim r1 As Range
- Range("A1").Select
- Selection.End(xlDown).Select
-
- rf = ActiveCell.Offset(0, 23).Address
- rtxt = "x2:" & rf
- Set r1 = Range(rtxt)
- r1.Select
- Selection.FillDown
-
- '值貼上
- Selection.Copy
- Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
- :=False, Transpose:=False
- 公式_UTZ
- 貼上
- '刷子
-
-
- Windows("Tester_COEE&UTZ_" & plan_date & "_DailyRawData.xls").Activate
- Workbooks("Tester_COEE&UTZ_" & plan_date & "_DailyRawData.xls").Close False
-
-
-
- Next
-
- MsgBox ("手動拉日期")
-
-
- End Sub
複製代碼
可抓取網段上資料.rar (227.96 KB)
|
|