请帮助Excel 2003宏 [英] Please help with Excel 2003 Macro
问题描述
我是Visual Basic的新手,我正在尝试在Excel 2003中执行以下操作:
我有一个类似于以下内容的spreasheet:
名称代码值
名称代码值
名称代码值
名称代码值
名称代码值
名称代码值
名称代码值
名称代码值
名称代码值
名称代码值
名称代码值
名称代码值
名称代码值
名称代码值
名称代码值
我要做的是写一个从顶部单元格开始的宏在value列中找到第一个空白行并返回一个Autosum,然后转到下一个空白行并再次返回Autosum,依此类推到电子表格的底部。我尝试了以下代码:
Dim a
Selection.End(xlDown).Select
ActiveCell.Offset(1,0)。选择
a = ActiveCell.Value
如果a ="""然后
应用.SendKeys("%=〜")
结束如果
这适用于第一个空白行。我遇到的问题是,当我尝试将循环放入(或在If语句之后的任何内容)时,它似乎正在跳过If语句并首先执行下一个命令。
任何人都可以帮忙吗?
Hi
您可以尝试以下内容:
它总结了第3列中的值
Sub ForQue()
Dim a,i1
Dim iCol As Integer
Dim iStartRow As Long
Dim iLastRow As Long
iCol = 3'您需要总和的列
iStartRow = 1
iLastRow =范围("A65536" ;)。结束(xlUp).Row
对于i1 = 1到iLastRow + 1
如果Len(Cells(i1,iCol).Value)= 0那么
Cells( i1,iCol).Formula =" = SUM(C& iStartRow&" C"& i1-1&")"
iStartRow = i1 + 1
结束如果
下一个i1
结束子
干杯
Shasur
I am very new to Visual Basic and I am tryin to do the following in Excel 2003:
I have a spreasheet that looks something like the following:
name Code Value
name Code Value
name Code Value
name Code Value
name Code Value
name Code Value
name Code Value
name Code Value
name Code Value
name Code Value
name Code Value
name Code Value
name Code Value
name Code Value
name Code Value
What i am trying to do is write a macro that starts in the top cell of the value column and finds the first blank row and returns an Autosum, then goes to the next blank row and returns an Autosum again and so on to the bottom of the spreadsheet. I have tried the following code:
Dim a
Selection.End(xlDown).Select
ActiveCell.Offset(1, 0).Select
a = ActiveCell.Value
If a = "" Then
Application.SendKeys ("%=~")
End If
This works fine for the first blank row. The problem I have is that when i try to put a loop in (or anything after the If statement) it seems to be skipping the If statement and carrying out the next command first.
Can anyone help?
Hi
You can try something like the following:
It sums up the value in Column 3
Sub ForQue() Dim a, i1 Dim iCol As Integer Dim iStartRow As Long Dim iLastRow As Long iCol = 3 'Column where you need the sum iStartRow = 1 iLastRow = Range("A65536").End(xlUp).Row For i1 = 1 To iLastRow + 1 If Len(Cells(i1, iCol).Value) = 0 Then Cells(i1, iCol).Formula = "=SUM(C" & iStartRow & ":C" & i1 - 1 & ")" iStartRow = i1 + 1 End If Next i1 End SubCheers
Shasur
这篇关于请帮助Excel 2003宏的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!