+ -
当前位置:首页 → 问答吧 → vba怎么用if函数来进行计算?

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

作者: xuehao   发布时间: 2011-08-03

你好,好像还是没有用。什么原因,望告知!

作者: lcjy11185   发布时间: 2011-08-03

用了vba 就没必要用太多公式了吧。。。

作者: jiminyanyan   发布时间: 2011-08-03

引用:
原帖由 jiminyanyan 于 2011-8-3 19:16 发表
用了vba 就没必要用太多公式了吧。。。
请您看看我的附件,如果要得出J列的数据,该如何做?

作者: 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

作者: raven_81   发布时间: 2011-08-03

相关阅读 更多