Excel精英培训网

 找回密码
 注册
数据透视表40+个常用小技巧,让你一次学会!
查看: 2950|回复: 11

[已解决]我自己尝试写了个VBA求大神 们指导,我门都还没入

[复制链接]
发表于 2017-8-7 20:11 | 显示全部楼层 |阅读模式
本帖最后由 釜底抽薪 于 2017-8-8 11:20 编辑

Sub 11()
Dim i&
For i = 2 To [i65536].End(3).Row
  If Cells(i, 4) = "检修井" Then

   If Cells(i, 12)= <>"" Then

    Cells(i, 10) + Cells(i, 12)/1000 Else
      Cells(i, 10) + Cells(i, 14)/1000

     end if
    end if
  end sub
   

     还没写完,上面IF运行后在与Cells(i,9) 做比较,大于Cells(i,9),Cells(i,9)就是黄色文本填充
最佳答案
2017-8-8 10:52
本帖最后由 AmoKat 于 2017-8-8 10:57 编辑
釜底抽薪 发表于 2017-8-8 09:54
我试了下 不行 我把表格 传上来了

我的VBA程式有繁體字,請修改為簡體字就可以


Sub 检修井管径检查()
    Dim i&
    For i = 2 To [i65536].End(3).Row
        If Cells(i, "D") = "检修井" And Cells(i, "L") <> "" Then
            If Cells(i, "I") < Cells(i, "J") + Cells(i, "L") / 1000 Or _
               Cells(i, "I") < Cells(i, "J") + Cells(i, "N") / 1000 Then
                Cells(i, "I").Interior.Color = vbYellow
            Else
                Cells(i, "I").Interior.Color = xlNone
            End If
        End If
    Next
End Sub


'色彩常数
'
'说明 常数
'黑  vbBlack
'红  vbRed
'绿  vbGreen
'黄  vbYellow
'蓝  vbBlue
'紫红 vbMagenta
'蓝绿 vbCyan
'白  vbWhite



无标题.png
excel精英培训的微信平台,每天都会发送excel学习教程和资料。扫一扫明天就可以收到新教程
发表于 2017-8-7 21:00 | 显示全部楼层
回复

使用道具 举报

发表于 2017-8-7 21:01 | 显示全部楼层
黃色的本文沒有看到,另外您的代碼有點問題,所以不是很清楚您的需求
回复

使用道具 举报

发表于 2017-8-8 07:15 | 显示全部楼层
本帖最后由 AmoKat 于 2017-8-8 07:16 编辑

Sub 檢修井管徑檢查()
    Dim i&
    For i = 2 To [i65536].End(3).Row
        If Cells(i, "D") = "檢修井" And Cells(i, "L") <> "" Then
            If Cells(i, "I") >= Cells(i, "J") + Cells(i, "L") * 2 / 1000 Or _
               Cells(i, "I") >= Cells(i, "J") + Cells(i, "N") / 1000 Then
                Cells(i, "I").Interior.Color = vbYellow
            Else
                Cells(i, "I").Interior.Color = xlNone
            End If
        End If
    Next
End Sub


'色彩常數
'
'說明 常數
'黑  vbBlack
'紅  vbRed
'綠  vbGreen
'黃  vbYellow
'藍  vbBlue
'紫紅 vbMagenta
'藍綠 vbCyan
'白  vbWhite
回复

使用道具 举报

 楼主| 发表于 2017-8-8 09:50 | 显示全部楼层
idnoidno 发表于 2017-8-7 21:00
請問可以把檔案丟上來以便了解嗎

我已经上传了。文本我设置了条件格式,  本来条件格式也行,就是设置了条件格式的话,在插入行,复制行,条件格式的范围有变化。

调查表格- .rar

59.06 KB, 下载次数: 3

回复

使用道具 举报

 楼主| 发表于 2017-8-8 09:54 | 显示全部楼层
AmoKat 发表于 2017-8-8 07:15
Sub 檢修井管徑檢查()
    Dim i&
    For i = 2 To .End(3).Row

我试了下 不行 我把表格 传上来了

调查表格- .rar

59.06 KB, 下载次数: 6

回复

使用道具 举报

发表于 2017-8-8 10:29 | 显示全部楼层
釜底抽薪 发表于 2017-8-8 09:54
我试了下 不行 我把表格 传上来了

Sub 井管()
    Dim i&
    For i = 2 To [i65536].End(3).Row
        If Cells(i, "D") = "检修井" Then    '注意简繁体
            If Cells(i, "I") >= Cells(i, "J") + Cells(i, IIf(Cells(i, 12) = "", 14, 12)) / 1000 Then
                Cells(i, "I").Interior.Color = vbYellow
            Else
                Cells(i, "I").Interior.Color = xlNone
            End If
        End If
    Next
End Sub

=======================
1.) 注意简繁体
2.) 疑似 颜色要调换一下

回复

使用道具 举报

发表于 2017-8-8 10:32 | 显示全部楼层
  1. Sub aaa()
  2. Dim i&, n#
  3. For i = 2 To [a65536].End(3).Row
  4.   Cells(i, 9).Interior.Pattern = xlNone
  5.   If Cells(i, 4) = "检修井" Then
  6.     If Cells(i, 12) <> "" Then n = Cells(i, 12) Else n = Cells(i, 13)
  7.     If Cells(i, 9) < Cells(i, 10) + n / 1000 Then Cells(i, 9).Interior.Color = vbRed
  8.   End If
  9. Next i
  10. End Sub
复制代码
回复

使用道具 举报

发表于 2017-8-8 10:33 | 显示全部楼层
If Cells(i, "D") Like "[检檢]修井" Then
这样 简繁体 都可以 , 但是从数据规范的角度 , 不推荐.
回复

使用道具 举报

发表于 2017-8-8 10:52 | 显示全部楼层    本楼为最佳答案   
本帖最后由 AmoKat 于 2017-8-8 10:57 编辑
釜底抽薪 发表于 2017-8-8 09:54
我试了下 不行 我把表格 传上来了

我的VBA程式有繁體字,請修改為簡體字就可以


Sub 检修井管径检查()
    Dim i&
    For i = 2 To [i65536].End(3).Row
        If Cells(i, "D") = "检修井" And Cells(i, "L") <> "" Then
            If Cells(i, "I") < Cells(i, "J") + Cells(i, "L") / 1000 Or _
               Cells(i, "I") < Cells(i, "J") + Cells(i, "N") / 1000 Then
                Cells(i, "I").Interior.Color = vbYellow
            Else
                Cells(i, "I").Interior.Color = xlNone
            End If
        End If
    Next
End Sub


'色彩常数
'
'说明 常数
'黑  vbBlack
'红  vbRed
'绿  vbGreen
'黄  vbYellow
'蓝  vbBlue
'紫红 vbMagenta
'蓝绿 vbCyan
'白  vbWhite



回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

小黑屋|手机版|Archiver|Excel精英培训 ( 豫ICP备11015029号 )

GMT+8, 2024-4-25 09:32 , Processed in 0.179960 second(s), 10 queries , Gzip On, Yac On.

Powered by Discuz! X3.4

Copyright © 2001-2020, Tencent Cloud.

快速回复 返回顶部 返回列表