复制单元格范围vba
我有一个在Excel单元格的范围,我需要复制到同一工作表,但在另一列。
列E中的第29 – 44行需要复制到B列。
但是,复制的单元格不能包含值EGA 。
我想我需要迭代,但我不知道如何。
我怎么能这样做?
尝试这样的事情:
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
如何使用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