【问题标题】:copy cell range vba复制单元格范围vba
【发布时间】:2011-02-02 12:37:28
【问题描述】:

我在 Excel 中有一系列单元格,我需要将它们复制到同一张工作表但在另一列中。

需要将 E 列的第 29 - 44 行复制到 B 列。很简单。

但是,复制的单元格不能包含值 EGA

我想我需要迭代,但我不知道如何。

我该怎么做?

【问题讨论】:

    标签: excel vba


    【解决方案1】:

    试试这样的:

    Sub NoEGA()
        Dim vArr As Variant
        Dim j As Long
    
        vArr = Range("E29:E44")
        For j = 1 To UBound(vArr)
            If UCase(vArr(j, 1)) = "EGA" Then vArr(j, 1) = ""
        Next j
    
        Range("B29:B44") = vArr
    End Sub
    

    【讨论】:

      【解决方案2】:

      使用 InStr 怎么样?

      Sub CopyWithoutEGA()
          Dim Tests As Range
          Set Tests = Range("E29")
          Dim Output As Range
          Set Output = Range("B29")
          Dim Contents As String
      
          Dim nIndex As Long
          Dim nMaxIndex As Long
      
          nIndex = 1
          nMaxIndex = 16
      
          While nIndex <= nMaxIndex
              Contents = Tests.Cells(nIndex, 1)
              If (InStr(1, Contents, "EGA", 1)) Then
                  Output.Cells(nIndex, 1) = "This contains EGA"
              Else
                  Output.Cells(nIndex, 1) = Contents
              End If
              nIndex = nIndex + 1
          Wend
      End Sub
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2015-11-26
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多