楼主 wudixin96 |
针对花花提出的问题,可以不予考虑,只要求简单的数值格式,整数或带小数点的数值就行 了。其它格式不要求,略显麻烦了,如果加其它格式。
答案正确:奖励1-3个技能分 截止时间:2011年8月12日 回帖要求:以代码形式贴上。d.gif |
2楼 涅磐86970 |
上个烂的。。 Private Sub Worksheet_Change(ByVal Target As Range) For i = 1 To Len(Target.Value) If Mid(Target.Value, i, 1) >= "0" And Mid(Target.Value, i, 1) <= "9" Then Target.Characters(Start:=i, Length:=1).Font.FontStyle = "加粗" Else Target.Characters(Start:=i, Length:=1).Font.FontStyle = "常规" End If If i > 1 Then If Mid(Target.Value, i, 1) = "." And Mid(Target.Value, i - 1, 1) >= "0" And Mid(Target.Value, i - 1, 1) <= "9" And Mid(Target.Value, i + 1, 1) >= "0" And Mid(Target.Value, i + 1, 1) <= "9" Then Target.Characters(Start:=i, Length:=1).Font.FontStyle = "加粗" End If End If Next End Sub |
3楼 gdgzlyh |
- Private Sub Worksheet_Change(ByVal Target As Range)
- Dim i As Integer
- Dim s As Integer
- Dim l As Integer
- Dim t1, t2
- If Target.Count > 1 Then Exit Sub
- s = 0: l = 0
- For i = 1 To Len(Target)
- t1 = Mid(Target, i, 1)
- t2 = IIf(i < Len(Target), Mid(Target, i + 1, 1), "")
- If s = 0 And IsNumeric(t1) Then
- s = i
- End If
- If s > 0 And Not IsNumeric(t1) And t1 <> "." Then
- l = i
- With Target.Characters(Start:=s, Length:=l - s).Font
- .FontStyle = "加粗"
- .ColorIndex = 3
- End With
- s = 0: l = 0
- ElseIf s > 0 And IsNumeric(t1) And i = Len(Target) Then
- l = i + 1
- With Target.Characters(Start:=s, Length:=l - s).Font
- .FontStyle = "加粗"
- .ColorIndex = 3
- End With
- s = 0: l = 0
- ElseIf s > 0 And t1 = "." And Not IsNumeric(t2) And t2 <> "" Then
- l = i
- With Target.Characters(Start:=s, Length:=l - s).Font
- .FontStyle = "加粗"
- .ColorIndex = 3
- End With
- s = 0: l = 0
- ElseIf s > 0 And t1 = "." And i = Len(Target) Then
- l = i
- With Target.Characters(Start:=s, Length:=l - s).Font
- .FontStyle = "加粗"
- .ColorIndex = 3
- End With
- s = 0: l = 0
- End If
- Next i
- End Sub
|
4楼 liuguansky |
- Private Sub Worksheet_Change(ByVal Target As Range)
- If Target.Cells.Count = 1 Then
- If Target.Column = 1 Then
- Dim m, k%, s&
- With CreateObject("vbscript.regexp")
- .Global = True
- .MultiLine = True
- .Pattern = "(\d*[\.\d]{0,1}\d+)"
- If .test(Target.Value) Then
- arr = Split(.Replace(Target.Value, vbTab), vbTab)
- For Each m In .Execute(Target.Value)
- k = k + 1: s = s + Len(arr(k - 1))
- With Target.Characters(s + 1, Len(m)).Font
- .Size = 16
- .ColorIndex = 47
- End With
- s = s + Len(m)
- Next
- End If
- End With
- End If
- End If
- End Sub
对小数点的处理,是这样的吗? |
5楼 terryfei |
来看看~想知道答案! |
6楼 zemon |
学习下 |
7楼 xyf2210 |
最复杂的,无敌啥时候教教俺正则呀- Private Sub Worksheet_Change(ByVal Target As Range)
-
- Dim i&
- For i = 1 To Len(Target)
- If Mid(Target, i, 3) Like "[0-9]" & "." & "[0-9]" Then
- Target.Characters(Start:=i, Length:=3).Font.Bold = True
- Target.Characters(Start:=i, Length:=3).Font.Color = vbRed
- ElseIf Mid(Target, i, 1) Like "[0-9]" Then
- Target.Characters(Start:=i, Length:=1).Font.Bold = True
- Target.Characters(Start:=i, Length:=1).Font.Color = vbRed
- End If
- Next
- End Sub
|