2016-03-30 6 views
-2

私はVBAを使用してセルから値を見つけ、対応する値を別のセルに配置する方法は?サーバー名:ジョブ名:

と仮定セルAが

ControlM以下の言及などのデータ含まれている別のセルに対応する値をセルから値を検索し、配置するためのコードを書くために助けを必要とし(OKでない日に終了した障害のタイプを、longrunning ...)

セルの内容から失敗の種類を確認し、別のセルに特定の関連値を配置します。

答えて

0

したい式は次のとおりです。

=RIGHT(A1,LEN(A1)-FIND("~",SUBSTITUTE(A1,":","~",LEN(A1)-LEN(SUBSTITUTE(A1,":",""))))) 

明らかにあなたが参照しているものは何でもセルの「A1」に変更します。

あなたはあなたが表示されるように大切にしたいセルにこの数式を挿入するVBAを使用することができます

0

私は、これはあなたが望むものであることを確認していないが、これ試してみてください。以下は

Sub printErrorCode() 

Dim errorType, errorCode As Variant 'define two variant variable to store errors and codes 
Dim errorPosition As Integer 'define errorPosition which will return the position of the searched string 

With ThisWorkbook.Sheets("YourSheetName") 'In my example I worked with a single sheet so I will avoid specifying the workbook and the sheet in every line 

errorType = .Range("ListOfErrorsRange").Value 'store possible error types 
errorCode = .Range("ListOfErrorCodesRange").Value 'store associated codes 

For i = LBound(errorType) To UBound(errorType) 'from the first error type to the last 
    errorPosition = InStr(1, .Range("YourStringRange"), errorType(i, 1), vbTextCompare) 'return the position of errorType String in YourRange string if found, or 0 if not found 
    If errorPosition <> 0 Then 'if errorPosition <>0 it found the string 
     .Range("YourStringRange").Offset(0,1).Value = errorCode(i, 1) 'if errorType string found return corresponding errorCode 
     Exit Sub 'exit the routine 
    End If 
Next i 

MsgBox "Error Not Found In List" 'if errorPosition = 0 for all i, then the Error was not on the list of errors 

End With 

End Sub 
0

ですセルA1に

あなたはモジュール

Public Function getcontent(r As Range) As String 
    str1 = InStr(r.Cells.Value, "failure type") 
    If str1 > 0 Then 
     str2 = Mid(r.Cells.Value, str1 + 13, Len(r.Cells.Value)) 
     getcontent = str2 
    Else 
     getcontent = "" 
    End If 
End Function 

に貼り付ける必要があり、コードは、コンテンツの "障害のタイプ(エンドOKではない、longrunning ...):サーバー名:ジョブ名ControlM" を前提とし

セルA2で、= getcontent(A1)

あなたは失敗タイプのコンテンツだけを取得します。

これはあなたの要件に沿ったものです。

関連する問題