但是我執行時停在這行~還沒能載入檔案~可以幫忙看看嗎~~~謝謝~~~~~
Sub Ex()
Dim AR, SH As Worksheet
Dim i As Long, Msg As Variant, W As Single, M As Single
Set SH = ActiveSheet
With SH.UsedRange
.Columns("S").Clear
AR = .Columns("S")
End With
AR(1, 1) = "PASS/FAIL" <-停在此行
For i = 2 To UBound(AR)作者: happycoccolin 時間: 2014-12-19 11:02
3.另外,若是針對"R"的部分,在P欄會出現"r0603_hxx"(xx是變數) or "r0603"的字元,一樣可以判斷出來嗎?(原先是預設為:mx_r0603)
Select Case Right(Trim(Cells(i, "P")), 4) ' P欄後4碼字串
Case "0402" '零件大小
W = 0.0625 '功率(W)
Case "0603"
W = 0.1
Case "0805"
W = 0.125
Case "1206"
W = 0.25
Case "1210"
W = 0.3333
Case "1812"
W = 0.5
Case "2010"
W = 0.75
Case "2512"
W = 1
End Select
4.以下這段,若是Kohm & Mohm中間帶一個空格(K ohm & M ohm),一樣可以判斷出來嗎?
If Msg = "0OHM" Or Msg = " OHM" Then '『非0 ohm』:ohm類的字元前面可能帶空格,部分未帶空格
'IF(O1="R",IF(OR((M1="0ohm"),(M1="0 ohm")),IF(Q1平方*N1< W參閱項目2*0.6,PASS,FAIL)))
M = Val(Cells(i, "M"))
Msg = Cells(i, "Q") ^ 2 * Cells(i, "N") < W * 0.6
Else '<>"0OHM" Or <> " OHM"
'M1需判斷值:以歐姆值計算.若為Kohm:其值×1000、若為Mohm:其值×1000000)
'例如:M1=2.64Kohm=2.64*1000=2640
M = Val(Cells(i, "M")) * 10000 'Kohm
If Msg = "MOHM" Then M = Val(Cells(i, "M")) * 1000000
'IF(O1="R",IF(OR((M1<>"0ohm"),(M1<>"0 ohm")),IF(Q1平方/2640-2640*N1<0.0625*0.6,PASS,FAIL)))
Msg = Cells(i, "Q") ^ 2 / M - M * Cells(i, "N") < W * 0.6
End If
filein = Application.GetOpenFilename(FileFilter:="Excel 活頁簿 (*.xlsx),*.xlsx", Title:="請選擇要比對的檔案")
If Not TypeName(filein) = "String" Then Exit Sub '取消則結束
--------------------------------------
If MsgBox("請問是否要儲存檔案?", vbYesNo) = vbYes Then
fileout = Application.GetSaveAsFilename(FileFilter:="Excel 活頁簿 (*.xlsx),*.xlsx", Title:="另存為新檔")
If Not TypeName(fileout) = "String" Then Exit Sub '取消則結束
.SaveAs fileout, FileFormat:=xlWorkbookDefault
End If
--------------------------------------作者: GBKEE 時間: 2014-12-22 14:22
Case "R"
Msg = Split(Cells(i, "P"), "_") 'Msg = P欄中用 "_" 字串分割傳回的陣列
If UBound(Msg) = 0 Then '陣列元素只有一個,P欄中沒有"_"的字元
Msg = Split(Cells(i, "P"), "_")(0)
ElseIf UBound(Msg) > 0 Then 'P欄中有"_"的字元
Msg = Split(Cells(i, "P"), "_")(1)
If Mid(UCase(Msg), 1, 1) = "H" Then
'"r0603_hxx"(xx是變數) : r+後四碼字串_hxx
Msg = Split(Cells(i, "P"), "_")(0)
End If
End If
W = 0
Select Case Right(Trim(Msg), 4) ' P欄後4碼字串
Case "0402" '零件大小
W = 0.0625 '功率(W)
Case "0603"
W = 0.1
Case "0805"
W = 0.125
Case "1206"
W = 0.25
Case "1210"
W = 0.3333
Case "1812"
W = 0.5
Case "2010"
W = 0.75
Case "2512"
W = 1
End Select
'**********************************************************************
'4.以下這段,若是Kohm & Mohm中間帶一個空格(K ohm & M ohm),一樣可以判斷出來嗎?
'**************************************************************************
Msg = UCase(Right(Trim(Cells(i, "M")), 5))
If Msg = "K OHM" Or Msg = "M OHM" Then '讀取5個字元,取得歐姆單位
'M1需判斷值:以歐姆值計算.若為Kohm:其值×1000、若為Mohm:其值×1000000)
'例如:M1=2.64Kohm=2.64*1000=2640
M = Val(Cells(i, "M")) * 10000 'Kohm
If Msg = "M OHM" Then M = Val(Cells(i, "M")) * 1000000
'IF(O1="R",IF(OR((M1<>"0ohm"),(M1<>"0 ohm")),IF(Q1平方/2640-2640*N1<0.0625*0.6,PASS,FAIL)))
Msg = Cells(i, "Q") ^ 2 / M - M * Cells(i, "N") < W * 0.6
End If
If Not IsNumeric(Msg) Then '5個字元,非歐姆單位
Msg = UCase(Right(Trim(Cells(i, "M")), 4)) '讀取4個字元,取得歐姆單位
If Msg = "0OHM" Or Msg = " OHM" Then '『非0 ohm』:ohm類的字元前面可能帶空格,部分未帶空格
'IF(O1="R",IF(OR((M1="0ohm"),(M1="0 ohm")),IF(Q1平方*N1< W參閱項目2*0.6,PASS,FAIL)))
M = Val(Cells(i, "M"))
Msg = Cells(i, "Q") ^ 2 * Cells(i, "N") < W * 0.6
ElseIf Msg = "KOHM" Or Msg = "MOHM" Then
'M1需判斷值:以歐姆值計算.若為Kohm:其值×1000、若為Mohm:其值×1000000)
'例如:M1=2.64Kohm=2.64*1000=2640
M = Val(Cells(i, "M")) * 10000 'Kohm
If Msg = "MOHM" Then M = Val(Cells(i, "M")) * 1000000
'IF(O1="R",IF(OR((M1<>"0ohm"),(M1<>"0 ohm")),IF(Q1平方/2640-2640*N1<0.0625*0.6,PASS,FAIL)))
Msg = Cells(i, "Q") ^ 2 / M - M * Cells(i, "N") < W * 0.6
End If
End If
If Not IsNumeric(Msg) Then '4個字元,非歐姆單位
Msg = UCase(Right(Trim(Cells(i, "M")), 3)) '剩下3個字元,最小的歐姆單位
M = Val(Cells(i, "M"))
Msg = Cells(i, "Q") ^ 2 * Cells(i, "N") < W * 0.6