|
大家好,我是Excel VBA的初学者,我根据自己的工作需求准备编写一个小程序改善工作效率,但是遇到一个问题,不知道怎么解决了,具体如下
● 背景
- 我有两个格式差不多的工作表,需要核对两个工作表的差异
- 核对的条件: 通过两个工作表中A和B列判断是否一样,然后把工作表1中C列的结果写入工作表2的C列
● 程序
Sub SJHE()
Dim sht_1, sht_2 As Worksheet
Set sht_1 = bok.Worksheets("工作表1")
Set sht_2 = bok.Worksheets("工作表2")
Dim a, b As Integer
a = 3
b = 3
Dim rng1_1, rng1_2, rng1_3 As Range
Set rng1_1 = sht_1.Cells(a, "A")
Set rng1_2 = sht_1.Cells(a, "B")
Set rng1_3 = sht_1.Cells(a, "C")
Dim rng2_1, rng2_2, rng2_3 As Range
Set rng5_1 = sht_2.Cells(b, "A")
Set rng5_2 = sht_2.Cells(b, "B")
Set rng5_3 = sht_2.Cells(b, "C")
Do While sht_2.Cells(b, "A") <> ""
Do While sht_1.Cells(a, "A") <> ""
If rng1_1 = rng2_1 And rng1_2 = rng5 2_2 Then
rng1_3 = rng2_3
End If
a = a + 1
Loop
b = b + 1
Loop
End Sub
请各位大神帮忙看一下需要怎么改正?我自己实在是没看出来要怎么修正,谢谢! |
|