Excel精英培训网

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

[已解决]在宏里面怎么套用AND函数,麻烦各位老师给看下

[复制链接]
发表于 2017-4-27 17:41 | 显示全部楼层 |阅读模式
本帖最后由 976190982 于 2017-4-30 16:29 编辑

=AND($A662<>"",$B662<>"",$C662<>"",$D662="")   应用到=$H$662:$H$666    填充红色
已上这个AND函数   用宏怎么写   。麻烦各位老师给个解决方案

Tiaoxingma.zip (482.44 KB, 下载次数: 1)
发表于 2017-4-27 18:18 | 显示全部楼层
回复

使用道具 举报

 楼主| 发表于 2017-4-27 19:27 | 显示全部楼层
327718098 发表于 2017-4-27 18:18
上附件,说清楚要求

因为特殊性,表格打开就要对指定区域清除内容,但是我对要清除的单元格区域做了条件格式。每一次打开条件格式就没有 。

因此我想问问怎么把条件格式用宏来编写 ,这样每一次打开清除内容后再执行条件格式就好

可惜我对vba不了解  所以求救各位大咖
回复

使用道具 举报

发表于 2017-4-27 19:43 | 显示全部楼层
本帖最后由 327718098 于 2017-4-27 19:46 编辑
976190982 发表于 2017-4-27 19:27
因为特殊性,表格打开就要对指定区域清除内容,但是我对要清除的单元格区域做了条件格式。每一次打开条件 ...

没附件谁知道要怎么写。range("A662")<>"" and range("B662")<>"" and range("C662") <>"" and range("D662") =""
这就是你要大and 格式

回复

使用道具 举报

发表于 2017-4-27 21:44 | 显示全部楼层
代码如下:
  1. Sub myfill()
  2. If [a662] <> "" And [b662] <> "" And [c662] <> "" And [d662] = "" Then
  3.     [h662:h666].Interior.ColorIndex = 3
  4. End If
  5. End Sub
复制代码


回复

使用道具 举报

 楼主| 发表于 2017-4-29 12:35 | 显示全部楼层
本帖最后由 976190982 于 2017-4-29 12:47 编辑
327718098 发表于 2017-4-27 19:43
没附件谁知道要怎么写。range("A662")"" and range("B662")"" and range("C662") "" and range("D662") = ...

好 吧     谢谢   我稍后上传



回复

使用道具 举报

 楼主| 发表于 2017-4-29 12:36 | 显示全部楼层

谢谢  我试试
回复

使用道具 举报

 楼主| 发表于 2017-4-29 12:47 | 显示全部楼层
本帖最后由 976190982 于 2017-4-29 12:48 编辑
327718098 发表于 2017-4-27 19:43
没附件谁知道要怎么写。range("A662")"" and range("B662")"" and range("C662") "" and range("D662") = ...

已上传附件
回复

使用道具 举报

 楼主| 发表于 2017-4-29 12:48 | 显示全部楼层
976190982 发表于 2017-4-29 12:35
好 吧     谢谢   我稍后上传

已经上传   谢谢

回复

使用道具 举报

发表于 2017-4-29 15:50 | 显示全部楼层    本楼为最佳答案   
本帖最后由 327718098 于 2017-5-4 07:24 编辑
976190982 发表于 2017-4-29 12:48
已经上传   谢谢

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Application.EnableEvents=False
If Target.Count > 1 Then
    MsgBox "不能选中多个单元格"
    Cells(Target.Row, 1).Select
    End
    End If
If Cells(Target.Row, 1) <> "" And Cells(Target.Row, 2) <> "" And _
Cells(Target.Row, 3) <> "" And Cells(Target.Row, 4) <> "" Then
    If Target.Column = 5 Or Target.Column = 6 Or Target.Column = 7 Then
        MsgBox "当abcd列不为空时,EFG列不能输入"
        Cells(Target.Row, 1).Select
        End
    Else
    End
    End If
End If
If Cells(Target.Row, 1) <> "" And Cells(Target.Row, 2) <> "" And _
Cells(Target.Row, 3) <> "" Then
    If Target.Column = 5 Or Target.Column = 6 Or Target.Column = 8 Then
    MsgBox "当abc列不为空时,EFH列不能输入"
    Cells(Target.Row, 1).Select
    End
    Else
    End
    End If
End If
If Cells(Target.Row, 1) <> "" And Cells(Target.Row, 2) <> "" Then
    If Target.Column = 5 Or Target.Column = 7 Or Target.Column = 8 Then
    MsgBox "当ab列不为空时,EGH列不能输入"
    End
    Else
    End
    End If
End If
If Cells(Target.Row, 1) <> "" Then
    If Target.Column = 6 Or Target.Column = 7 Or Target.Column = 8 Then
     MsgBox "当a列不为空时,FGH列不能输入"
    Cells(Target.Row, 1).Select
    End If
End If
Application.EnableEvents=True
End Sub



回复

使用道具 举报

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

本版积分规则

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

GMT+8, 2024-4-23 18:45 , Processed in 0.358585 second(s), 10 queries , Gzip On, Yac On.

Powered by Discuz! X3.4

Copyright © 2001-2020, Tencent Cloud.

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