求助,VB操作excel
通过DSF工作簿中YSJ工作表C2单元格的日期,在其他工作表中查询相同的日期并定位在其向下一单元格,帮看一下代码,新手谢谢。Set xlbook = xlapp.Workbooks.Open(App.Path& "\dsf.xls", , , , "2011")
Set xlsheet = xlbook.Worksheets("YSJ")
Dim rng As Range, st, sh As Workbook, x
For x = 1 To 48
If Cells.Item(2, 3).Value <> "" Then
st = Cells.Item(2, 3).Value
For Eachsh In Sheets
If sh.Name<> "YSJ" Then
Set rng = sh.Cells.Find(st)
If Not rng Is Nothing Then
Application.Gotorng.Offset(x)
Exit For
End If
End If
Next
ActiveCell.FormulaR1C1 = "=SUMIFS(YSJ!C[-7],YSJ!C[-10],RC[-9],YSJ!C[-9],""汇总"")"
rng.Offset(x).Select
Selection.Copy
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Else
MsgBox "无记录": Exit Sub
End If
Next x