/ / Excel VBAでセルが数値かどうかを確認する[duplicate] - Excel、Excel、Excel、Excel

Excel VBAでセルが数値かどうかを確認する[duplicate] - excel、vba、excel-vba

以下のコードでは、私は数値の処理に取り組んでいます細胞の計算。時には、セルの1つ(たとえば、 "LosLimit")に "---"のような数値以外の値が含まれることがあります。セルが数値かどうかをチェックするにはどうすればいいですか?

数値であれば計算し、そうでなければ "MeasValue"から値を返す

Sub ReturnMarginal()

"UpdatebySUPERtoolsforExcel2016
Dim xOut As Worksheet
Dim xWb As Workbook
Dim xWks As Worksheet
Dim InterSectRange As Range
Dim lowLimCol As Integer
Dim hiLimCol As Integer
Dim measCol As Integer

Application.ScreenUpdating = False
Set xWb = ActiveWorkbook
For Each xWks In xWb.Sheets
xRow = 1
With xWks
FindString = "LowLimit"
If Not xWks.Rows(1).Find(FindString) Is Nothing Then
.Cells(xRow, 16) = "Meas-LO"
.Cells(xRow, 17) = "Meas-Hi"
.Cells(xRow, 18) = "Min Value"
.Cells(xRow, 19) = "Marginal"
LastRow = .UsedRange.Rows.Count
lowLimCol = Application.WorksheetFunction.Match("LowLimit", xWks.Range("1:1"), 0)
hiLimCol = Application.WorksheetFunction.Match("HighLimit", xWks.Range("1:1"), 0)
measLimCol = Application.WorksheetFunction.Match("MeasValue", xWks.Range("1:1"), 0)
.Range("P2:P" & lastRow).Formula = "=IF(ISNUMBER(" & .Cells(2, lowLimCol).Value2 & ")," & Cells(2, measLimCol).Address(False, False) & "-" & Cells(2, lowLimCol).Address(False, False) & "," & Cells(2, measLimCol).Address(False, False) & ")"


.Range("Q2:Q" & LastRow).Formula = "=" & Cells(2, hiLimCol).Address(False, False) & "-" & Cells(2, measLimCol).Address(False, False)

.Range("R2").Formula = "=min(P2,Q2)"
.Range("R2").AutoFill Destination:=.Range("R2:R" & LastRow)

.Range("S2").Formula = "=IF(AND(R2>=-3, R2<=3), ""Marginal"", R2)"
.Range("S2").AutoFill Destination:=.Range("S2:S" & LastRow)

End If

End With
Application.ScreenUpdating = True "turn it back on
Next xWks

End Sub

回答:

回答№1の場合は3

あなたの答えは疑問でした!たとえばtrueまたはfalseを返す関数isNumeric(variable_goes_here)があります。

if isNumeric(x) then msgbox("Woop!")

真を返し、あなたにメッセージボックスを与えます x = 45 もしスキップするならば x = "Not a number"