【问题标题】:Grabbing data without duplicating the information VBA抓取数据而不复制信息 VBA
【发布时间】:2017-01-26 16:21:16
【问题描述】:

我正在为下面留空的数据创建大量列标题。

表格示例

Col 1 | Col 2 | Col3 | Col 4 |
blank | info | blank| info  |

我用来收集这些空白并将它们粘贴到“debug.print”中的代码以显示需要信息的列。最终结果应该是:
缺少的信息是:
Col1
Col3
它比我的例子大很多,请有人帮忙看看我哪里出错了,因为它会在我循环时复制信息。

Do Until iCol = 34
    If Cells(iRow, iCol) = "" Then
        CellMissInfo = CellMissInfo & CurrTitleCol & ": " & vb_
        Debug.Print (CellMissInfo)
    End If
    iCol = iCol + 1
Loop

编辑: 更多代码帮助

iRow = 3
iCol = 22
lastRow = Application.WorksheetFunction.CountA _
(Range("B2", Range("B" & Rows.Count).End(xlUp)))

Do While iRow <= lastRow

    If CurrPipeC <> RGB(242, 220, 219) Then 'Pipeline Color'
        Do Until iCol = 34
'HERE is my problem'
            If Cells(iRow, iCol) = "" Then
                CellMissInfo = CellMissInfo & CurrTitleCol & ": " & vb_
            End If
            iCol = iCol + 1
        Loop

新想法:也许如果我将列创建为一个数组,然后通过 LBound 运行到 Ubound 以将列名添加到一起?

【问题讨论】:

  • 不清楚你是如何设置 CurrTitleCol 的,好像没有设置?另外,iRow 和 iCol 是如何初始化的?
  • CurrTitleColl = 单元格(1,iCol)。我循环每一行 iRow。然后使用 iCol 移动到下一列进行检查。

标签: vba excel


【解决方案1】:

问题是您在遍历列时连接字符串并且每次都打印字符串。

在我看来,你有两个选择:要么建立一个包含所有缺失数据的字符串,然后在最后打印出来。或者在找到时打印出每个丢失的项目

选项 1: 建立一个字符串并在最后打印:

Do Until iCol = 34
    If Cells(iRow, iCol) = "" Then
        CellMissInfo = CellMissInfo & CurrTitleCol & ": " & vb_
    End If
    iCol = iCol + 1
Loop
Debug.Print (CellMissInfo)

选项 2: 找到丢失的每件物品后打印出来

Do Until iCol = 34
    If Cells(iRow, iCol) = "" Then
        CellMissInfo = CurrTitleCol & ": " & vb_
        Debug.Print (CellMissInfo)
    End If
    iCol = iCol + 1
Loop

【讨论】:

  • 第一个选项我仍然得到重复,第二个选项我有 34 列和 300 行,我设置了一封电子邮件,每次一行完成时发送给人们。我认为第二行将是我唯一的选择。我希望可能有一种方法可以阻止它
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-10-27
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-02-08
相关资源
最近更新 更多