VBA高手请进

sljz 2006-05-11 02:54:03
数据 单双
5,278.27
5,312.18
5,282.40
5,286.40
5,233.70
5,193.94
5,241.19


现在有这个excel表,我现在需要一个vba,能判断数据列中数字的个位数字是单还是双,然后在单双列显示“单”或者“双”,同时如果是单的,单元格背景颜色为红色,如果双,背景颜色为蓝色

谢谢
...全文
261 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
liulang0808 2006-05-12
  • 打赏
  • 举报
回复
Private Sub CommandButton1_Click()
finalRow = Range("A65536").End(xlUp).Row
For i = 2 To finalRow

If (length( Cells(i, 1)) mod 2) = 0 Then
Cells(i, 2) = "双"
With Cells(i, 2).Interior
.ColorIndex = 41
.Pattern = xlSolid
End With
Else
Cells(i, 2) = "单"
With Cells(i, 2).Interior
.ColorIndex = 3
.Pattern = xlSolid
End With
End If
Next i
End Sub
northwolves 2006-05-11
  • 打赏
  • 举报
回复
Sub Macro1()
Range("b2").Select
Selection .FormulaR1C1 = "=IF(MOD(RC1,2)>1,""单"",""双"")"
Selection.Interior.ColorIndex = IIf(Selection.Offset(0, -1) Mod 2 >= 1, 5, 3)
Selection.AutoFill Destination:=Range("b2:b" & Range("a65536").End(xlUp).Row), Type:=xlFillDefault
End Sub
sljz 2006-05-11
  • 打赏
  • 举报
回复
我用函数+条件格式 已经实现效果了,感谢楼上兄弟,回头结贴
yumanqing 2006-05-11
  • 打赏
  • 举报
回复
楼上的对
Arqui 2006-05-11
  • 打赏
  • 举报
回复
Private Sub CommandButton1_Click()
finalRow = Range("A65536").End(xlUp).Row
For i = 2 To finalRow
myValue = Cells(i, 1)
myValue = Int(myValue)
MyStr = Right(myValue, 1)
a = MyStr Mod 2
If a = 0 Then
Cells(i, 2) = "双"
With Cells(i, 2).Interior
.ColorIndex = 41
.Pattern = xlSolid
End With
Else
Cells(i, 2) = "单"
With Cells(i, 2).Interior
.ColorIndex = 3
.Pattern = xlSolid
End With
End If
Next i
End Sub

2,462

社区成员

发帖
与我相关
我的任务
社区描述
VBA(Visual Basic for Applications)是Visual Basic的一种宏语言,是在其桌面应用程序中执行通用的自动化(OLE)任务的编程语言。
社区管理员
  • VBA
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧