|
Sub 更新价格表1()
Dim jgl As Long, maxrow As Long
Dim x As String
On Error Resume Next
With Me
maxrow = Application.WorksheetFunction.Match("末尾行", Sheets("价格表更新模板").Range("a:a"), 0)
x = .Cells(1, 9) '供应商位置
Set sht = Sheets("价格表")
jgl = Application.WorksheetFunction.Match(x, Sheets("价格表").Range("a1:zz1"), 0) '(定义价格数据列号)
'sht.Cells(2, jgl) = Application.WorksheetFunction.VLookup("更新日期", Sheets("更新价格表模板").Range("a:z"), 5, 0) '更新日期
'sht.Cells(4, jgl) = Application.WorksheetFunction.VLookup(Sheets("价格表").Range("a4"), Sheets("更新价格表模板").Range("a:f"), 5, 0)
sht.Cells(2, jgl).Resize(100000, jgl) = ""
Sheets("更新价格表模板").Cells(2, 7).Resize(100000, jgl) = ""
For i = 2 To maxrow
n = n + 1
fzlhh = n + 1
'sht.Cells(i, jgl) = Application.WorksheetFunction.VLookup(Sheets("价格表").Cells(fzlhh, 1), Sheets("更新价格表模板").Range("a:f"), 5, 0)
y = Application.WorksheetFunction.Match(Sheets("更新价格表模板").Cells(fzlhh, 1), sht.Range("a:a"), 0)
sht.Cells(y, jgl) = Sheets("价格表更新模板").Cells(n, 5)
Next i
For j = 2 To 1000
n1 = n1 + 1
fzlhh2 = n1 + 1
Sheets("更新价格表模板").Cells(j, 7) = Application.WorksheetFunction.VLookup(Sheets("更新价格表模板").Cells(fzlhh2, 1), sht.Range("a:zz"), jgl, 0)
Next j
End With
End Sub
然后用vlookup 能写但是数据位置很多都不对.
Sub 更新价格表() '数据会错位
Dim jgl As Long, maxrow As Long
Dim hh As Long
Dim x As String
Dim jg As Long
On Error Resume Next
With Me
maxrow = Application.WorksheetFunction.Match("末尾行", Sheets("价格表").Range("a:a"), 0)
x = .Cells(1, 9) '供应商位置
Set sht = Sheets("价格表")
jgl = Application.WorksheetFunction.Match(x, Sheets("价格表").Range("a1:zz1"), 0) '(定义价格数据列号)
'sht.Cells(2, jgl) = Application.WorksheetFunction.VLookup("更新日期", Sheets("更新价格表模板").Range("a:z"), 5, 0) '更新日期
'sht.Cells(4, jgl) = Application.WorksheetFunction.VLookup(Sheets("价格表").Range("a4"), Sheets("更新价格表模板").Range("a:f"), 5, 0)
sht.Cells(2, jgl).Resize(100000, jgl) = ""
Sheets("更新价格表模板").Cells(2, 7).Resize(100000, jgl) = ""
For i = 2 To 10000
n = n + 1
fzlhh = n + 1
sht.Cells(i, jgl).Formula = Application.WorksheetFunction.VLookup(Sheets("价格表").Cells(fzlhh, 1), Sheets("更新价格表模板").Range("a:f"), 5, 0)
Next i
For j = 2 To 3000
n1 = n1 + 1
fzlhh2 = n1 + 1
Sheets("更新价格表模板").Cells(j, 7) = Application.WorksheetFunction.VLookup(Sheets("更新价格表模板").Cells(fzlhh2, 1), sht.Range("a:zz"), jgl, 0)
If Sheets("更新价格表模板").Cells(j, 7) <> Sheets("更新价格表模板").Cells(j, 5) Then
Sheets("更新价格表模板").Cells(j, 7).ColorIndex = 3
End If
Next j
End With
End Sub
|
|