|
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件 ★ 免费下载 ★ ★ 使用帮助★
Sub 按钮1_Click()
Dim lastRow As Integer
Dim monthCol As Integer
lastRow = IIf(Sheet1.Range("B65535").End(xlUp).Row + 1 = 3, 4, Sheet1.Range("B65535").End(xlUp).Row + 1)
Application.EnableEvents = False
Sheet1.Range("A" & lastRow) = lastRow - 3
Sheet2.Range("A3:F3").Copy
Sheet1.Range("B" & lastRow).PasteSpecial xlPasteValues
monthCol = findMonth(Sheet2.Range("G3").Text)
If monthCol <> 0 Then
Sheet1.Cells(lastRow, monthCol) = Sheet2.Range("H3")
Sheet1.Cells(lastRow, monthCol + 1) = Sheet2.Range("I3")
Else
MsgBox "无对应时间,数据错误!"
End If
Application.EnableEvents = True
End Sub
Private Function findMonth(mon As String) As Integer
Dim i As Integer
For i = 8 To 56 Step 2
If Sheet1.Cells(2, i).Text = mon Then
findMonth = i
Exit Function
End If
Next
findMonth = 0
End Function
Sub 按钮2_Click()
Dim lastRow As Integer
Dim i As Integer
Dim contractRow As Integer
Dim got As Boolean
Dim monthCol As Integer
lastRow = Sheet1.Range("B65535").End(xlUp).Row + 1
got = False
For i = 4 To lastRow
If Sheet1.Range("B" & i) = Sheet2.Range("A7") Then
got = True
contractRow = i
Exit For
End If
Next
If Not got Then
MsgBox "没有对应的合同号!"
Exit Sub
End If
Application.EnableEvents = False
monthCol = findMonth(Sheet2.Range("G7").Text)
If monthCol <> 0 Then
Sheet1.Cells(contractRow, monthCol) = Sheet2.Range("H7")
Sheet1.Cells(contractRow, monthCol + 1) = Sheet2.Range("I7")
Else
MsgBox "无对应时间,数据错误!"
End If
Application.EnableEvents = True
End Sub
|
|