我希望有人可以帮我编码。我有2个数据工作表。
第1周:“销售更正” 第2周:“按期间划分的新销售额”
两者均以以下格式设置。如果客户使用wks 1,我需要代码将每个月的数据与wks 2上的数据进行比较。如果不匹配,则将替换wks 2上的数据。
Account# month1 month2 month3....etc.
account1 $ $ $
account2 $ $ $
account3 $ $ $
如果我开始为每张纸上的列号,行号和行结果创建变量,我可能可以使它起作用,但是我知道我应该能够更有效地做到这一点。我可以使用列标题来匹配数据吗?
下面是我开始写的内容。
firstrow_saleschanges = Worksheets("Sales Corrections").Cells.Find("Customer Name", SearchOrder:=xlByRows, SearchDirection:=xlUp).Row
lastrow_saleschanges = Worksheets("Sales Corrections").Cells.Find("*", SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row
firstcol_saleschanges = Worksheets("Sales Corrections").Cells.Find("*", SearchOrder:=xlColumns, SearchDirection:=xlNext, LookIn:=xlValues).Column
lastcol_saleschanges = Worksheets("Sales Corrections").Cells.Find("*", SearchOrder:=xlColumns, SearchDirection:=xlPrevious, LookIn:=xlValues).Column
For numrow = firstrow_saleschanges To lastrow_saleschanges
customer_account = Worksheets("Sales Corrections").Cells(numrow, "A")
sales_row_match = Worksheets("New Sales by Period").Cells.Find(customer_account, SearchOrder:=xlByRows, SearchDirection:=xlUp).Row
For colcount = firstcol_saleschanges To lastcol_saleschanges
If Worksheets("Sales Corrections").Cells(numrow, firstcol_saleschanges) <> Worksheets("New Sales by Period").Cells(sales_row_match, firstcol_saleschanges) Then
Worksheets("Sales Corrections").Cells(numrow, firstcol_saleschanges).Copy
Worksheets("New Sales by Period").Cells(sales_row_match, firstcol_saleschanges).PasteSpecial xlPasteValues
End If
Next colcount
Next numrow