vba怎么用if函数来进行计算?
时间:2011-08-03
来源:互联网
我从家里学了自动加入公式的代码,因为数据很多,难住了。特请大家帮忙!
vba里怎么用if公式进行计算.rar(9.09 KB)
附件

2011-8-3 17:33, 下载次数: 6
作者: lcjy11185 发布时间: 2011-08-03
对数据格式都不够了解啊!
Private Sub Worksheet_Change(ByVal Target As Range)
Dim h As Integer
Dim i As Integer
With Target
h = .Row
If h <= 6 Then Exit Sub
If .Column = 1 Then
For i = .Row To .Row + .Rows.Count - 1
If Cells(i, 1) = "" Then
Range(Cells(i, 2), Cells(i, 26)).ClearContents
Else
Cells(i, 10).Value = "=iif(month(cells(i,3)>=9,date(year(cells(i,3))+7,9,1),date(year(cells(i,3))+6,9,1)"
End If
Next
End If
End With
End Sub
Private Sub Worksheet_Change(ByVal Target As Range)
Dim h As Integer
Dim i As Integer
With Target
h = .Row
If h <= 6 Then Exit Sub
If .Column = 1 Then
For i = .Row To .Row + .Rows.Count - 1
If Cells(i, 1) = "" Then
Range(Cells(i, 2), Cells(i, 26)).ClearContents
Else
Cells(i, 10).Value = "=iif(month(cells(i,3)>=9,date(year(cells(i,3))+7,9,1),date(year(cells(i,3))+6,9,1)"
End If
Next
End If
End With
End Sub
作者: xuehao 发布时间: 2011-08-03
你好,好像还是没有用。什么原因,望告知!
作者: lcjy11185 发布时间: 2011-08-03
用了vba 就没必要用太多公式了吧。。。
作者: jiminyanyan 发布时间: 2011-08-03
引用:
原帖由 jiminyanyan 于 2011-8-3 19:16 发表用了vba 就没必要用太多公式了吧。。。
作者: lcjy11185 发布时间: 2011-08-03
工作表J列先设置日期格式
Private Sub Worksheet_Change(ByVal Target As Range)
Dim h As Integer
Dim i As Integer
Dim x As Integer
With Sheets("sheet1")
x = .[a:a].Find("*", , , , , xlPrevious).Row
End With
With Target
h = .Row
If h <= 6 Then Exit Sub
If .Column = 1 Then
For i = .Row To x
If Cells(i, 1) = "" Then
Range(Cells(i, 2), Cells(i, 26)).ClearContents
Else
Cells(i, 10) = "=if(month(R" & i & "C3)>=9,date(year(R" & i & "C3)+7,9,1),date(year(R" & i & "C3)+6,9,1))"
End If
Next
End If
End With
End Sub
Private Sub Worksheet_Change(ByVal Target As Range)
Dim h As Integer
Dim i As Integer
Dim x As Integer
With Sheets("sheet1")
x = .[a:a].Find("*", , , , , xlPrevious).Row
End With
With Target
h = .Row
If h <= 6 Then Exit Sub
If .Column = 1 Then
For i = .Row To x
If Cells(i, 1) = "" Then
Range(Cells(i, 2), Cells(i, 26)).ClearContents
Else
Cells(i, 10) = "=if(month(R" & i & "C3)>=9,date(year(R" & i & "C3)+7,9,1),date(year(R" & i & "C3)+6,9,1))"
End If
Next
End If
End With
End Sub
作者: raven_81 发布时间: 2011-08-03
相关阅读 更多
热门阅读
-
office 2019专业增强版最新2021版激活秘钥/序列号/激活码推荐 附激活工具
阅读:74
-
如何安装mysql8.0
阅读:31
-
Word快速设置标题样式步骤详解
阅读:28
-
20+道必知必会的Vue面试题(附答案解析)
阅读:37
-
HTML如何制作表单
阅读:22
-
百词斩可以改天数吗?当然可以,4个步骤轻松修改天数!
阅读:31
-
ET文件格式和XLS格式文件之间如何转化?
阅读:24
-
react和vue的区别及优缺点是什么
阅读:121
-
支付宝人脸识别如何关闭?
阅读:21
-
腾讯微云怎么修改照片或视频备份路径?
阅读:28