excel macro loop line data, Excel all the statistics the number of rows of data sheet

Sub fun1()
'统计每一个sheet有多少行数据
Set s1 = Sheets("Sheet1")
'totalok = 0
For i = 1 To Sheets.Count
s1.Cells(i, 1) = Sheets(i).Name
r = Sheets(i).Range("A65535").End(xlUp).Row

s1.Cells(i, 2) = r
If i > 4 Then
totalok = totalok + r
End If
Next
s1.Cells(1, 3) =totalok
 End subsequent Sub

 
Sub Fun2 ()
     'a sheet table to check whether there is another loop in the sheet, 
'
check whether there names the OK ' the Set Sheet = Worksheets ( "Sheet251") the Set DBSH = Sheets ( " pd_port " ) ' the Set newSH = Sheets ( " (the CN) CHINA ") Cells ( . 1 , 12 is ) = Now () ' start time Dim I I = 2 the Do the While Cells (I, 2 ) <> " " NewCode = Trim ( the UCase (Cells (I,2))) newName = TRIM ( the UCase (Cells (I, . 4 ))) isAirPort = "" isSeaPort = "" isRailway = "" the PortType = 3 ' 0 port, an airport, train station 3 2 other the If the InStr (newName, " the APT " )> 0 the Then isAirPort = " Yes the AirPort " the PortType = . 1 End the If the If the InStr (newName, " the PT ") > 0 Then isSeaPort = "Yes SeaPort" PortType = 0 End If If InStr(newName, " RAILWAY") > 0 Then isRailway = "Yes Railway" PortType = 2 End If r1 = "code No" r2 = "name No" For j = 2 To 5192 dbCode = Trim(UCase(dbSH.Cells(j, 6))) dbName = Trim(UCase(dbSH.Cells(j, 4))) If PortType = 1 Then dbName = Replace(dbName, " Apt", " AIRPORT") newCode = Right(newCode, 3) newName = Replace(newName, " Apt", "") End If If dbCode = newCode Then r1 = "code Exist" End If If dbName = newName Then r2 = "name Exist" End If Next Cells(i, 12) = r1 Cells(i, 13) = r2 Cells(i, 14) = isAirPort Cells(i, 15) = isSeaPort Cells(i, 16) = isRailway Cells(i, 17) = PortType i = i + 1 Loop Cells(1, 13) = Now() ' 结束时间 End Sub
Sub fun3 () 
    
'a sheet table to check whether there is another loop in the sheet,
  '
check whether there names Test ' the Set Sheet = Worksheets ( "Sheet251") the Set DBSH = Sheets ( " pd_port " ) ' the Set newSH = Sheets ( " (the CN) CHINA ") Cells ( . 1 , 12 is ) = Now () ' start time Dim I I = 2 ' the Do the While Cells (I, 2) <>" " the For I = 1105 the To 1110 NewCode = Trim ( the UCase (Cells (I, 2 ))) newName "= Trim ( the UCase (Cells (I, . 4 ))) isAirPort = "" isSeaPort = "" isRailway = "" the PortType = 3 ' 0 port, an airport, train station 3 2 other the If the InStr (newName, " the APT " )> 0 the Then isAirPort = " Yes the AirPort " the PortType = . 1 End the If the If the InStr (newName, the PT ") > 0 Then isSeaPort = "Yes SeaPort" PortType = 0 End If If InStr(newName, " RAILWAY") > 0 Then isRailway = "Yes Railway" PortType = 2 End If r1 = "code No" r2 = "name No" For j = 2 To 5192 dbCode = Trim(UCase(dbSH.Cells(j, 6))) dbName = Trim(UCase(dbSH.Cells(j, 4))) If PortType = 1 Then dbName = Replace(dbName, " Apt", " AIRPORT") newCode = Right(newCode, 3) newName = Replace(newName, " Apt", "") End If If dbCode = newCode Then r1 = "code Exist" End If If dbName = newName Then r2 = "name Exist" End If Next Cells(i, 12) = r1 Cells(i, 13) = r2 Cells(i, 14) = isAirPort Cells(i, 15) = isSeaPort Cells(i, 16) = isRailway Cells(i, 17) = PortType 'i = i + 1 'Loop Next Cells(1, 13) = Now() ' 结束时间 End Sub
Sub Fun4()
    ' 查国家是否存在

     ' Set Sheet = Worksheets("Sheet251")
     Set dbSH = Sheets("pd_country")
     Set newSH = Sheets("Country Name")
    newSH.Cells(1, 3) = Now() ' 开始时间
    
    For i = 2 To 250
       ' Sheet.Rows(i).Cells (0)
       ' Print Sheet.Cells(i, 1)
      ' Print Worksheets("Sheet251").Cells(i, 1).Value
      newCode = UCase(newSH.Cells(i, 1))
      newName = UCase(newSH.Cells(i, 2))
      
      ResultCode = "code No"
      ResultName = "name No"
      For j = 1 To 255
        dbCode = UCase(dbSH.Cells(j, 5))
        dbName = UCase(dbSH.Cells(j, 3))
        
        ' MsgBox dbValue + "---" + newValue
        If dbCode = newCode Then
            ResultCode = "code Exist"
        End If
        
        If dbName = newName Then
            ResultName = "name Exist"
        End If
        
        
      Next
      
      newSH.Cells(i, 3) = ResultCode
      newSH.Cells(i, 4) = ResultName
      

      
      newSH.Cells(1, 4) = Now() ' 结束时间
    Next
End Sub

 

Guess you like

Origin www.cnblogs.com/q149072205/p/11281003.html
Recommended