excell



Public Sub test()
Dim i, j As Integer
Dim province, value, province2, value2 As String

For i = 2 To Sheet2.UsedRange.Rows.Count
    province = Sheet2.Cells(i, 1)
    value = Sheet2.Cells(i, 4)
        
        If InStr(1, province, "省") > 0 Then
            Sheet5.Cells(i, 1) = Left(province, InStr(1, province, "省") - 1)
            Sheet5.Cells(i, 2) = value
        Else
            If InStr(1, province, " ") > 0 Then
            Sheet5.Cells(i, 1) = Left(province, InStr(1, province, " ") - 1)
            Sheet5.Cells(i, 2) = value
            
            Else
            
            Sheet5.Cells(i, 1) = province
            Sheet5.Cells(i, 2) = value
            End If
        End If
        
    
Next i

End Sub



你可能感兴趣的:(Excel)