各位前輩:
小弟做了一個EXCEL巨集,在執行時會時好時壞。
請教不知應該如何處裡- Sub COMBIN()
- '
-
-
- Cells.Select
-
- Cells.Replace What:=" ", Replacement:="", LookAt:=xlPart, SearchOrder:= _
- xlByRows, MatchCase:=False
-
- Range("c1").Select
- ActiveCell.FormulaR1C1 = "chkno"
-
- Call chkno
-
- Range("d1").Select
-
- End Sub
- Sub chkno()
- '
- '
- Dim myrow As Long
- Dim i As Integer
- myrow = Range("a1").End(xlDown).Row
- For i = 2 To myrow
-
- Selection.NumberFormatLocal = "@"
-
-
- 'If Not IsError(Cells(i, 1) <= 99999 And Cells(i, 2) <= 999) Then
- If Not IsError(Cells(i, 1).NumberFormatLocal = "0" And Cells(i, 4).NumberFormatLocal = "0") Then
- Cells(i, 3).Value = _
- String(6 - Len(Cells(i, 1)), "0") & Cells(i, 1) & String(4 - Len(Cells(i, 2)), "0") & Cells(i, 2)
-
- ElseIf Not IsError(Cells(i, 1).NumberFormatLocal = "@" And Cells(i, 4).NumberFormatLocal = "0") Then
- Cells(i, 3).Value = _
- Cells(i, 1) & String(4 - Len(Cells(i, 2)), "0") & Cells(i, 2)
-
- ElseIf Not IsError(Cells(i, 1).NumberFormatLocal = "0" And Cells(i, 2).NumberFormatLocal = "@") Then
- Cells(i, 3).Value = _
- String(6 - Len(Cells(i, 1)), "0") & Cells(i, 3) & String(4 - Len(Cells(i, 2)), "0") & Cells(i, 2)
- Else
-
- Cells(i, 3).Value = Cells(i, 1) & Cells(i, 2)
- End If
-
- Next i
-
- End Sub
複製代碼 如附件
COMBIN.rar (9.88 KB)
|