VBA在两列中一组单元格的条件级联 [英] VBA Conditional concatenate of a group of cells in two columns

查看:36
本文介绍了VBA在两列中一组单元格的条件级联的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这对我来说很遥不可及.这是工作表布局的示例:

This is far to advanced for me to figure out. Here is an example of the worksheet layout:

Row#    ColA    ColB                                 
23      7       Description 
24      8       Description 
25      
26              For cases with  
27              SpecialOptionDesc = Yes
28      9       Description 
29      
30              For cases with  
31              SomeOptionDesc = Yes
32              and 
33              AnotherOptionDesc = No
34      9       Description 
35      
36      10      Description 

当它们出现在"For case with"中时,我需要在ColB中合并信息,并在其下面的单元格中.信息需要最终显示在ColA中具有标识号的行上.因此,在这种情况下,将ColB第26、27、28行全部复制"或以任何方式复制到ColB第28行中.同样,CollB第30至34行将全部位于ColB第34行上.旧行(26、27、30,31,33)可以删除,也可以混在一起.这些行上的数据将不再需要.

I'm need to consolidate the information in ColB when the them "For cases with" appears, with the cells below it. The information needs to end up on the row that has the identifying number in ColA. So in this case ColB Rows 26, 27, 28, will all be "copied" or whatever into ColB row 28. Likewise, ColB Rows 30 though 34 will all be on ColB row 34. The old rows (26, 27, 30, 31, 33) can be deleted mashed together or whatever. No data on those rows will be needed any longer.

推荐答案

我实际上并没有编译并尝试使用Excel,但我认为即使不是全部,它也可以为您提供90%的解决方案.我要离开计算机一会儿,但是回来时会做一些测试.

I didn't actually compile this and try it Excel, but I think that it will get you 90% of the way there if not all the way. I am stepping away from the computer for a bit, but will do some testing when I get back.

Dim cellValue As String
Dim i As Integer
Dim j As Integer
Dim strResult As String

Const endRow As Integer = 500

For i = 1 To endRow
     If LCase(ActiveSheet.Cells(i, 2).Value) = "for cases with" Then
        j = 0
        strResult = ""

        While ActiveSheet.Cells(i + j, 1).Value = "" And i + j < endRow
            strResult = strResult + " " + ActiveSheet.Cells(i + j, 2).Value

            ' delete stuff after using
            ActiveSheet.Cells(i + j, 2).Value = ""

            j = j + 1
        Wend

        ActiveSheet.Cells(i + j, 2) = strResult + " " + ActiveSheet.Cells(i + j, 2)
     End If
Next i

这篇关于VBA在两列中一组单元格的条件级联的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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