我正在设计一个扑克培训应用程序,只是添加一些收尾 -
这可能更像是一个VBA问题但是,我有一个每个卡片值的列(每件套装中所有卡片从2到A),钻石和心脏颜色为红色。)
我理想地想要的是Hand和Flop列中显示的牌 - 以红色显示 - 也就是说,序列中最后一个字符为♥或♦的任何一对字符
作为参考,“手”栏的公式为:
=F2&" "&F3
和'翻牌'专栏:
=F4&" "&F5&" "&F6
我已经尝试了条件格式化,但这突出了整个单元格,而不仅仅是特定的字符 - 我尝试了以下VBA代码,每当我尝试运行它时冻结了我的Excel:
Function GetColorText(pRange As Range) As String
'Updateby20141105
Dim xOut As String
Dim xValue As String
Dim i As Long
xValue = pRange.Text
For i = 1 To VBA.Len(xValue)
If pRange.Characters(i, 1).Font.Color = vbRed Then
xOut = xOut & VBA.Mid(xValue, i, 1)
End If
Next
GetColorText = xOut
End Function
答案 0 :(得分:0)
试试这个:
Public Enum Suits
spade = 9824
heart = 9829
diamond = 9830
club = 9827
End Enum
Sub ColorSuits(ByRef c As Range)
Dim s() As String
Dim i As Integer
Dim x As Integer, y As Integer
s = Split(c.Value, " ")
For i = LBound(s) To UBound(s)
x = InStr(c.Value, s(i))
y = Len(s(i))
c.Characters(x, y).Font.Color = SuitColor(s(i))
Next i
End Sub
Function SuitColor(ByVal s As String)
Select Case Right(s, 1)
Case ChrW(heart), ChrW(diamond)
SuitColor = vbRed
Case Else
SuitColor = vbBlack
End Select
End Function
Sub Test()
Dim c As Range
For Each c In Selection
ColorSuits c
Next c
End Sub