使用vba过滤excel数据

时间:2016-06-05 06:01:54

标签: excel vba excel-vba

我的概念首先是我必须在excel中输入文本作为引擎(12,3)然后从g13到结束列必须搜索0,*如果发现包含0或*的特定列应该读取值出现在第3行和第4行的文本值,它应该放在(13,3)我已经解释了图像文件中的概念spreadsheet image我也写了代码,但结果不达到水平请帮忙这个项目。

Dim searchRange As Range
Dim C As Range
Dim FinalRow As Range
Dim firstaddress As String
With Cells(12, 3)
.Value = "Engine"
.Font.Size = 14
.Font.Bold = True
End With
Dim lastrow As Long
lastrow = Cells(Rows.Count, 1).End(xlUp).Row
Dim lastColumn As Integer
lastColumn = ActiveSheet.Cells(2, Columns.Count).End(xlToLeft).Column


For i = 13 To lastrow
Set searchRange = Range("G13:ZZ20000")
Set Rng = searchRange.Find(What:="0", LookIn:=xlValues, LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:=False)
firstaddress = Rng.Address
Rng.Offset(i, -5).Value = Rng.Offset(-11, ActiveCell.Column).Value
Next i

关心, 卡菲基恩

1 个答案:

答案 0 :(得分:1)

你可以试试这个

Option Explicit

Sub main()
    Dim cell As Range
    Dim lastrow As Long, lastColumn As Long, i As Long
    Dim strng As String, resStrng As String

    With ActiveSheet
        With .Cells(12, 3)
            .Value = "Engine"
            .Font.Size = 14
            .Font.Bold = True
        End With

        lastrow = .Cells(.Rows.Count, "G").End(xlUp).Row
        lastColumn = .Cells(2, .Columns.Count).End(xlToLeft).Column

        For i = 13 To lastrow
            resStrng = ""
            For Each cell In .Range(.Cells(i, "G"), .Cells(i, lastColumn))
                If cell.Value = "*" Or cell.Value = 0 Then
                    strng = .Cells(2, cell.Column) & .Cells(3, cell.Column)
                    If InStr(resStrng, strng) = 0 Then resStrng = resStrng & strng & "&"
                End If
            Next cell
            If resStrng <> "" Then .Cells(i, 3) = Left(resStrng, Len(resStrng) - 1)
        Next i
    End With

End Sub