ªð¦^¦Cªí ¤W¤@¥DÃD µo©«

VBA¥¨¶°°õ¦æ®É¦n®ÉÃa¡C

VBA¥¨¶°°õ¦æ®É¦n®ÉÃa¡C

¦U¦ì«e½ú¡G
¤p§Ì°µ¤F¤@­ÓEXCEL¥¨¶°¡A¦b°õ¦æ®É·|®É¦n®ÉÃa¡C
½Ð±Ð¤£ª¾À³¸Ó¦p¦ó³B¸Ì
  1. Sub COMBIN()
  2. '
  3.      
  4.    
  5.     Cells.Select
  6.         
  7.     Cells.Replace What:=" ", Replacement:="", LookAt:=xlPart, SearchOrder:= _
  8.         xlByRows, MatchCase:=False
  9.    
  10.     Range("c1").Select
  11.     ActiveCell.FormulaR1C1 = "chkno"
  12.    
  13.     Call chkno
  14.    
  15.      Range("d1").Select
  16.    
  17. End Sub
  18. Sub chkno()
  19. '
  20. '
  21. Dim myrow As Long

  22. Dim i As Integer
  23.     myrow = Range("a1").End(xlDown).Row
  24.     For i = 2 To myrow
  25.       
  26.         Selection.NumberFormatLocal = "@"
  27.         
  28.         
  29.        'If Not IsError(Cells(i, 1) <= 99999 And Cells(i, 2) <= 999) Then
  30.         If Not IsError(Cells(i, 1).NumberFormatLocal = "0" And Cells(i, 4).NumberFormatLocal = "0") Then
  31.           Cells(i, 3).Value = _
  32.           String(6 - Len(Cells(i, 1)), "0") & Cells(i, 1) & String(4 - Len(Cells(i, 2)), "0") & Cells(i, 2)
  33.          
  34.        ElseIf Not IsError(Cells(i, 1).NumberFormatLocal = "@" And Cells(i, 4).NumberFormatLocal = "0") Then
  35.           Cells(i, 3).Value = _
  36.           Cells(i, 1) & String(4 - Len(Cells(i, 2)), "0") & Cells(i, 2)
  37.          
  38.        ElseIf Not IsError(Cells(i, 1).NumberFormatLocal = "0" And Cells(i, 2).NumberFormatLocal = "@") Then
  39.           Cells(i, 3).Value = _
  40.           String(6 - Len(Cells(i, 1)), "0") & Cells(i, 3) & String(4 - Len(Cells(i, 2)), "0") & Cells(i, 2)
  41.        Else
  42.                  
  43.           Cells(i, 3).Value = Cells(i, 1) & Cells(i, 2)
  44.        End If
  45.               
  46.     Next i
  47.   
  48. End Sub
½Æ»s¥N½X
¦pªþ¥ó COMBIN.rar (9.88 KB)
lionliu

¥»©«³Ì«á¥Ñ lionliu ©ó 2014-5-15 11:18 ½s¿è

¦^´_ 1# lionliu
§Úªº¥D­n°ÝÃD¬OCÄæ¥ÑA¡BBÄæ¦X¨Ö¦Ó¦¨
AÄ椣¨¬6¦ì¼Æ«e­±0 ¡ABÄ椣¨¬4¦ì¼Æ«e­±¸É0
      A              B                 C
23456          23      0234560023
­Y¬O¤å¦r¼Ò¦¡´N¥i¥H¡A­Y¼Æ¦r¼Ò¦¡´N·|¥X¿ù¡C
­Y¬O¥Ñ¥t¤@­Ó¥¨¶°©I¥s¥Dµ{¦¡¤@©w·|¿ù¡A³æ¯Â¶]¥Dµ{¦¡«h¤£¤@©w¡C
lionliu

TOP

¥»©«³Ì«á¥Ñ lionliu ©ó 2014-5-17 09:59 ½s¿è

¦^´_ 2# lionliu

¤£¦n·N«ä
¶i¤J»~°Ï
§Ú¥u­n±N cÄ檽±µ§ï¬°¤å¦r¬J¥i
Sub chkno()
Dim myrow As Long
Dim i As Integer
    myrow = Range("a1").End(xlDown).Row
    For i = 2 To myrow
       Cells(i, 3).NumberFormatLocal = "@"
        
          Cells(i, 3).Value = _
          String(6 - Len(Cells(i, 1)), "0") & Cells(i, 1) & String(4 - Len(Cells(i, 2)), "0") & Cells(i, 2)
End sub
³o¼Ë´Nok¤F
¤£ª¾·|¤£·|¦³bug«ÝÆ[¹î
lionliu

TOP

        ÀR«ä¦Û¦b : °µ¦n¨Æ¤£¯à¤Ö§Ú¤@¤H¡A°µÃa¨Æ¤£¯à¦h§Ú¤@¤H¡C
ªð¦^¦Cªí ¤W¤@¥DÃD