简体   繁体   English

excel VBA:如何跳过两个包含值的单元格之间的空白单元格?

[英]excel VBA : how to skip blank cells between 2 cells that contain values?

I am working out a button that can auto sum value at column C that column A = column B like the picture : PIC: I can only copy the value in column C (that the word in column A = column B) to column E so far. 我正在设计一个按钮,该按钮可以自动将C列的值累加到A列= B列,如图所示: 图片:我只能将C列中的值(即A列中的单词= B列)复制到E列,因此远。

the code 编码

Private Sub CommandButton2_Click()

Dim i As Integer, q As Integer

q = 2
For i = 3 To 100


Range("E" & q).Value = Range("b" & 3).Value

If Range("B" & i).Value = "A-RDL1" And Range("c" & i).Value = "OPEN" Then

Range("E" & i).Value = Range("d" & i).Value


End If
Next i


End Sub

the question 1) is how can I skip the blanks E9 to E17, so the numbers can be continuous? 问题1)如何跳过空格E9至E17,以便数字可以连续? (AFTER CLICK THE BOTTON) question 2) is it possible to auto sum the Numbers in column E instead of show each? (单击按钮后)问题2)是否可以自动对E列中的数字求和而不是显示每个数字?

Thanks a lot and sorry for my poor English... 非常感谢,抱歉我的英语不好。

1) Yes, you can skip those, just carry out a check in the cell value and compare to empty string: Range("").Value2 = "" . 1)是的,您可以跳过这些内容,只需对单元格值进行检查并与空字符串进行比较: Range("").Value2 = "" I personally prefer to do it like this though, to avoid false positives: Len(Trim(Range("").Value2)) = 0 . 我个人更喜欢这样做,以避免误报: Len(Trim(Range("").Value2)) = 0

2) Yes, you can do that. 2)是的,您可以这样做。 just declare an Integer variable or two and use that to carry out a running count of your values. 只需声明一个或两个Integer变量,然后使用该变量来对您的值进行连续计数。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM