循环遍历列:搜索大于0的值:写入值到另一个工作表时找到值并继续循环直到最后一行 [英] Loop Through Columns: Search for Value Greater Than 0: Write to Another Worksheet When Value Found and Continue Loop Until Last Row

查看:144
本文介绍了循环遍历列:搜索大于0的值:写入值到另一个工作表时找到值并继续循环直到最后一行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嘿伙计,

这是我在VBA的第三天,所以我是一个完整的新手而不是令人惊讶地遇到了一些麻烦。我正在尝试编写一段代码:

This is my third day with VBA, so i am a complete Newbie and not surprisingly am having some trouble. I am trying to write a section of code that:

1。循环遍历给定范围的单元格并搜索大于0的值。 

1. Loops through cells of a given range and searches for a value greater than 0. 

2。如果Value满足上述条件,则将该值复制到另一个工作表的另一个单元格中

2. If Value meets above condition then copy that value into another cell of a different sheet

3。继续搜索和复制单元格,直到找到并复制了该范围内的所有值

3. Continue searching and copying cells until all values from that range have been found and copied

此循环也在逐行进行的For Next循环中,并将其他值复制到另一个工作表中,直到它为止找到它将结束的最后一行

This Loop is also within a For Next Loop that goes row by row and copies other values into another sheet until it finds the last row where it will end

我已经设置了一个MsgBox测试,以查看初始循环(一个搜索值)找到的值,并且大多数情况下它似乎正常工作并返回正确的值,但在一些值后,它返回一个空白框,它应该
返回下一个找到的值

I have set up a MsgBox test to see what values the  initial Loop (one  searching for values)is finding and for the most part it seems to be working correctly and returning the right values but after some values it returns a blank box when it should be returning the next found value

我知道它不漂亮,但是嘿第三天。任何指针,提示建议和批评都受到欢迎和赞赏。不需要答案只是方向和一些提示

I know it is not pretty , but hey third day. Any pointers, tips suggestions and criticisms are welcomed and appreciated. Do not need the answer just direction and some hints

这是代码:

推荐答案

<我无法弄清楚你想要达到的目标。

I can't work out what you are trying to achieve.

循环中的代码"For Each RangeR In Range(DFirst,WLast)"仅在"RangeR.Value>"处理时才处理0" ;. (由If函数控制)

The code in the loop "For Each RangeR In Range(DFirst, WLast)" only processes if "RangeR.Value > 0". (Controlloed by If function)

循环中的代码"  For FirstLine = NewFirstLine To LastLine Step 1"无论RangeR的值如何,都会运行。这是它应该做的吗?

The code in the loop " For FirstLine = NewFirstLine To LastLine Step 1" runs irrespective of the value of RangeR. Is this what it is supposed to do?


这篇关于循环遍历列:搜索大于0的值:写入值到另一个工作表时找到值并继续循环直到最后一行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆