excel表,Alt+F11调用出vb语言处理excel表内容,很方便

Alt + F11调出来

然后可以右键插入窗体

Public Sub 处理数据_Click()

    Sheets(1).Columns(4).ColumnWidth = 12
    Sheets(1).Columns(5).ColumnWidth = 12
    
    Dim i, j As Integer
    Dim nRow As Integer
    nRow = ActiveSheet.[A65536].End(xlUp).Row
    Debug.Print nRow
    
    Dim nRowCount As Integer
    nRowCount = 1
    Dim strFlag1 As String
    Dim strFlag2 As String
    For i = 1 To nRow
        strFlag1 = Right(Sheets(1).Cells(i, 1), 3)
        strFlag2 = Left(Sheets(1).Cells(i, 1), 3)
        For j = 1 To nRow
            If (strFlag1 = Left(Sheets(1).Cells(j, 1), 3) And strFlag2 <> Right(Sheets(1).Cells(j, 1), 3)) Then
                Sheets(1).Cells(nRowCount, 4) = Sheets(1).Cells(i, 1)
                Sheets(1).Cells(nRowCount, 5) = Sheets(1).Cells(j, 1)
                nRowCount = nRowCount + 1
            End If
        Next j
    Next i
End Sub

  意思是处理这个sheet表1列,将处理结果,写入,第4列和第5列

 

原文地址:https://www.cnblogs.com/XiHua/p/15572838.html