如何跳过Excel VBA中的特定文本单元格

时间:2018-01-09 07:49:10

标签: excel vba excel-vba

当我在代码下面运行时,如何从合并中跳过特定的文本单元格。

Original data
S.No.   Clock No.      01   02  03  04  05  06
1       099566          W   P   p   P   P   P
2       282420          P   P   P   W   P   P
3       623738          P   P   W   L   P   P
4       406290          P   P   W   P   P   P
5       792585          P   P   P   P   P   w
6       097608          P   P   P   P   w   P
代码运行后

S.No.   Clock No.      01   02  03  04  05  06
1       099566          W   P   p   P   P   P
2       282420          P   P   P   W   P   P
3       623738          P   pl  pl  pl  P   P
4       406290          P   P   cl  clP P   P
5       792585          P   P   P   P   P   w
6       097608          P   P   P   P   w   P

我需要w text cell在运行代码时保持不变或跳过。

Sub LEAVE_MAP()
    Dim StartTime As Double
    Dim SecondsElapsed As Double

    'Remember time when macro starts
    StartTime = Timer
    'Dim dtStartTime As Date
    'dtStartTime = Now()

    Dim ws1 As Worksheet, ws2 As Worksheet
    Set ws1 = Sheets("main"): Set ws2 = Sheets("leave")
    Dim firstAddr As String
    Dim Rno As Integer, c As Range, rngEmp As Range, StartD As Long, EndD As Long
    For Rno = 2 To 20
        For Each c In ws1.Range("F1:AJ1")
            Set rngEmp = ws2.Range("A:A").Find(ws1.Range("B" & Rno))
            If Not rngEmp Is Nothing Then
                firstAddr = rngEmp.Address
                Do
                    StartD = rngEmp.Offset(, 7)
                    EndD = rngEmp.Offset(, 8)
                    If c.Value >= StartD And c.Value <= EndD Then
                        ws1.Cells(Rno, c.Column) = ws2.Range("C" & rngEmp.Row)
                    End If
                    Set rngEmp = ws2.Range("A:A").FindNext(rngEmp)
                'Loop While Not (Rng Is Nothing) And Rng.Address <> firstAddress
                Loop While rngEmp.Address <> firstAddr
            End If
        Next c
    Next Rno

    'MsgBox "Macro ran successfully in " & _
      FormatDateTime(Now() - dtStartTime, 3), vbInformation
    ' MsgBox "Dear Boss Givened Task Completed Successfully. Have a Nice Day"
    Set c = Nothing
    Set ws1 = Nothing: Set ws2 = Nothing
    'Determine how many seconds code took to run
    SecondsElapsed = Round(Timer - StartTime, 2)

    'Notify user in seconds
    MsgBox "Dear Boss This code ran Successfully in " & SecondsElapsed & " seconds", vbInformation
End Sub

0 个答案:

没有答案