五月天青色头像情侣网名,国产亚洲av片在线观看18女人,黑人巨茎大战俄罗斯美女,扒下她的小内裤打屁股

歡迎光臨散文網(wǎng) 會員登陸 & 注冊

實例35-兩表匹配,實例36-根據(jù)輸入值自動填充數(shù)據(jù) Excel表格VBA編程實例 代碼分享

2023-03-11 11:51 作者:凌霄百科_Excel辦公程序  | 我要投稿

實例35-兩表匹配


Private Sub CommandButton匹配1_Click()

'判斷參數(shù)不為空

Dim mc1 As Long

Dim mc2 As Long

With ThisWorkbook.Worksheets("操作界面")

If .Cells(2, "C").Value <> "" Then

mc1 = .Cells(2, "C").Value

Else

MsgBox "請輸入表1匹配列"

Exit Sub

End If

If .Cells(6, "C").Value <> "" Then

mc2 = .Cells(6, "C").Value

Else

MsgBox "請輸入表2匹配列"

Exit Sub

End If

End With

'清除匹配結(jié)果

With ThisWorkbook.Worksheets("匹配結(jié)果") '清除原列表數(shù)據(jù)

.UsedRange.ClearFormats

.UsedRange.ClearContents

End With

'獲取表1表2最大列號行號

Dim cmax1 As Long

Dim cmax2 As Long

cmax1 = ThisWorkbook.Worksheets("表1").UsedRange.Cells(ThisWorkbook.Worksheets("表1").UsedRange.Count).Column

cmax2 = ThisWorkbook.Worksheets("表2").UsedRange.Cells(ThisWorkbook.Worksheets("表2").UsedRange.Count).Column

Dim rmax1 As Long

Dim rmax2 As Long

rmax1 = ThisWorkbook.Worksheets("表1").UsedRange.Cells(ThisWorkbook.Worksheets("表1").UsedRange.Count).Row

rmax2 = ThisWorkbook.Worksheets("表2").UsedRange.Cells(ThisWorkbook.Worksheets("表2").UsedRange.Count).Row

Dim i, j

Dim addrow As Long

addrow = 1

Dim matchtext1 As String

Dim matchtext2 As String

Dim a1 As Integer '判斷循環(huán)時是否匹配成功

With ThisWorkbook.Worksheets("匹配結(jié)果") '清除原列表數(shù)據(jù)

For i = 1 To rmax2

a1 = 0

With ThisWorkbook.Worksheets("表2")

If .Cells(i, mc2) <> "" Then

matchtext2 = .Cells(i, mc2)

.Range(.Cells(i, 1), .Cells(i, cmax2)).Copy ThisWorkbook.Worksheets("匹配結(jié)果").Cells(addrow, 1)

With ThisWorkbook.Worksheets("表1")

For j = 1 To rmax1

If .Cells(j, mc1) <> "" Then

matchtext1 = .Cells(j, mc1)

If matchtext1 = matchtext2 Then

.Range(.Cells(j, 1), .Cells(j, cmax1)).Copy ThisWorkbook.Worksheets("匹配結(jié)果").Cells(addrow, cmax2 + 1)

a1 = 1

addrow = addrow + 1

End If

End If

Next j

End With

If a1 = 0 Then

addrow = addrow + 1

End If

End If

End With

Next i

End With

ThisWorkbook.Worksheets("匹配結(jié)果").Activate

End Sub

Private Sub CommandButton匹配2_Click()

'判斷參數(shù)不為空

Dim mc1 As Long

Dim mc2 As Long

With ThisWorkbook.Worksheets("操作界面")

If .Cells(2, "C").Value <> "" Then

mc1 = .Cells(2, "C").Value

Else

MsgBox "請輸入表1匹配列"

Exit Sub

End If

If .Cells(6, "C").Value <> "" Then

mc2 = .Cells(6, "C").Value

Else

MsgBox "請輸入表2匹配列"

Exit Sub

End If

End With

'清除匹配結(jié)果

With ThisWorkbook.Worksheets("匹配結(jié)果") '清除原列表數(shù)據(jù)

.UsedRange.ClearFormats

.UsedRange.ClearContents

End With

'獲取表1表2最大列號

Dim cmax1 As Long

Dim cmax2 As Long

cmax1 = ThisWorkbook.Worksheets("表1").UsedRange.Cells(ThisWorkbook.Worksheets("表1").UsedRange.Count).Column

cmax2 = ThisWorkbook.Worksheets("表2").UsedRange.Cells(ThisWorkbook.Worksheets("表2").UsedRange.Count).Column

Dim rmax1 As Long

Dim rmax2 As Long

rmax1 = ThisWorkbook.Worksheets("表1").UsedRange.Cells(ThisWorkbook.Worksheets("表1").UsedRange.Count).Row

rmax2 = ThisWorkbook.Worksheets("表2").UsedRange.Cells(ThisWorkbook.Worksheets("表2").UsedRange.Count).Row

Dim i, j

Dim addrow As Long

addrow = 1

Dim matchtext1 As String

Dim matchtext2 As String

Dim a1 As Integer '判斷循環(huán)時是否匹配成功

With ThisWorkbook.Worksheets("匹配結(jié)果") '清除原列表數(shù)據(jù)

For i = 1 To rmax1

a1 = 0

With ThisWorkbook.Worksheets("表1")

If .Cells(i, mc1) <> "" Then

matchtext1 = .Cells(i, mc1)

.Range(.Cells(i, 1), .Cells(i, cmax1)).Copy ThisWorkbook.Worksheets("匹配結(jié)果").Cells(addrow, 1)

With ThisWorkbook.Worksheets("表2")

For j = 1 To rmax2

If .Cells(j, mc2) <> "" Then

matchtext2 = .Cells(j, mc2)

If matchtext1 = matchtext2 Then

.Range(.Cells(j, 1), .Cells(j, cmax2)).Copy ThisWorkbook.Worksheets("匹配結(jié)果").Cells(addrow, cmax1 + 1)

a1 = 1

addrow = addrow + 1

End If

End If

Next j

End With

If a1 = 0 Then

addrow = addrow + 1

End If

End If

End With

Next i

End With

ThisWorkbook.Worksheets("匹配結(jié)果").Activate

End Sub


實例36-根據(jù)輸入值自動填充數(shù)據(jù)


Private Sub Worksheet_Change(ByVal Target As Range)

With ThisWorkbook.Worksheets("出庫表")

If Target.Column = 3 And Target.Row >= 6 And Target.Row <= 10 Then

Dim row1 As Long

row1 = Target.Row

If Target <> "" Then

Dim i

For i = 1 To ThisWorkbook.Worksheets("商品列表").Cells(1000000, 1).End(xlUp).Row

If Target.Value = ThisWorkbook.Worksheets("商品列表").Cells(i, 1) Then

.Cells(row1, 4) = ThisWorkbook.Worksheets("商品列表").Cells(i, 2)

.Cells(row1, 5) = ThisWorkbook.Worksheets("商品列表").Cells(i, 4)

Exit Sub

End If

Next i

MsgBox "未找到對應商品"

Target = ""

.Cells(row1, 4) = ""

.Cells(row1, 5) = ""

Else

.Cells(row1, 4) = ""

.Cells(row1, 5) = ""

End If

End If

End With

End Sub


實例35-兩表匹配,實例36-根據(jù)輸入值自動填充數(shù)據(jù) Excel表格VBA編程實例 代碼分享的評論 (共 條)

分享到微博請遵守國家法律
逊克县| 义乌市| 平顺县| 万载县| 黄龙县| 东方市| 临清市| 疏勒县| 东源县| 塔河县| 平陆县| 新民市| 渭南市| 中超| 乌海市| 阳谷县| 望谟县| 许昌县| 克东县| 青海省| 杭州市| 额济纳旗| 扬中市| 安宁市| 汕尾市| 太仆寺旗| 珲春市| 东阳市| 中卫市| 龙里县| 上高县| 新平| 仪陇县| 广宁县| 北海市| 沐川县| 彭山县| 永川市| 绥棱县| 牡丹江市| 六枝特区|