From 777ec3ebc0c93e1c5e66fb8f893b47967ba6f977 Mon Sep 17 00:00:00 2001 From: xiaochou164 Date: Tue, 15 Aug 2023 19:14:43 +0800 Subject: [PATCH] =?UTF-8?q?=E9=87=8D=E6=9E=84=E9=A6=96=E6=AC=A1=E6=8F=90?= =?UTF-8?q?=E4=BA=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 拉取电阻信息.vba | 68 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 68 insertions(+) create mode 100644 拉取电阻信息.vba diff --git a/拉取电阻信息.vba b/拉取电阻信息.vba new file mode 100644 index 0000000..d46150e --- /dev/null +++ b/拉取电阻信息.vba @@ -0,0 +1,68 @@ + +Sub 拉取电阻信息() +t = Timer + +Application.ScreenUpdating = False +Application.Calculation = xlCalculationManual + +Sql = "SELECT order_no,resistivity, " +Sql = Sql + "case when resistivity LIKE '>%' then SUBSTRING(resistivity,5,7) " +Sql = Sql + " when resistivity LIKE '%~%' then SUBSTRING_INDEX(resistivity,'~',1) " +Sql = Sql + " when resistivity LIKE '%-%' then SUBSTRING_INDEX(resistivity,'-',1) " +Sql = Sql + " when resistivity LIKE '<%' then SUBSTRING(resistivity,5,7) " +Sql = Sql + " when resistivity LIKE '>%' then SUBSTRING(resistivity,2,7) " +Sql = Sql + " when resistivity LIKE '<%' then SUBSTRING(resistivity,2,7) " +Sql = Sql + " when resistivity = '未分档' OR resistivity IS null then '未分档' end " +Sql = Sql + " from mes_sync.mes_disposable_qc_task " +Sql = Sql + " Union " +Sql = Sql + " SELECT order_no,resistivity, " +Sql = Sql + " case when resistivity LIKE '>%' then SUBSTRING(resistivity,5,7) " +Sql = Sql + " when resistivity LIKE '%~%' then SUBSTRING_INDEX(resistivity,'~',1) " +Sql = Sql + " when resistivity LIKE '%-%' then SUBSTRING_INDEX(resistivity,'-',1) " +Sql = Sql + " when resistivity LIKE '<%' then SUBSTRING(resistivity,5,7) " +Sql = Sql + " when resistivity LIKE '>%' then SUBSTRING(resistivity,2,7) " +Sql = Sql + " when resistivity LIKE '<%' then SUBSTRING(resistivity,2,7) " +Sql = Sql + " when resistivity = '未分档' OR resistivity IS null then '未分档' end " +Sql = Sql + " from mes_sync.mes_recycle_material_storage; " + + + +Call AutoRun '------获取数据库连接 + +Application.StatusBar = "正在拉取批次信息" +RES.Open Sql, conn '-----执行strSql 获得结果集 + +Application.StatusBar = "正在复制批次信息到表格" +Sheets("电阻信息").Cells(2, 1).CopyFromRecordset RES + +RES.Close '-------关闭结果集 必须要做的 + +Call closeConn + +尾行 = Cells(Rows.Count, "A").End(xlUp).row + +Application.StatusBar = "正在判断高低阻信息" +For i = 2 To 尾行 + 电阻 = Sheets("电阻信息").Cells(i, 3).Value + On Error Resume Next + + If 电阻 = "未分档" Then + Sheets("电阻信息").Cells(i, 4).Value = "低阻" + Else + If 电阻 >= 1.9 Then + Sheets("电阻信息").Cells(i, 4).Value = "高阻" + Else: Sheets("电阻信息").Cells(i, 4).Value = "低阻" + End If + End If +Next + + + +Application.ScreenUpdating = True +Application.Calculation = xlCalculationAutomatic + +Application.StatusBar = "拉取完成" + +MsgBox ("本次更新共花费:" & Format(Timer - t, "0.00") & "s!") +Application.StatusBar = False +End Sub