目的:在登录表中点击按钮会逐一将F20:G54 中的日期取出,在SAT LIST中查找相同日期,然后在下面对应的单元格中写入数据,结果,使用F8逐步执行可以得到结果,但是直接点击按钮运行则得不到结果。请各位帮忙。弄了一天了。
Private Sub CommandButton2_Click()
'Dim mdate As Date
'Dim ndate As Date
'Dim tdate As Date
'写入rawdata
'找出需要填写的行
jdno = Range("f3")
With Workbooks("RT 收件登录表 new2.xls").Worksheets("rawdata").Range("a1:a3000")
Set c = .Find(jdno, LookIn:=xlValues)
If Not c Is Nothing Then
daterow = c.Row
firstAddress1 = c.Address
Do
Set c = .FindNext(c)
Loop While Not c Is Nothing And c.Address <> firstAddress1
End If
End With
'找出要填写的列
'先判断月份(???适用新建档案,不适用修改档案)
Set mrow = Worksheets("schedule").Range("b1").End(xlDown).Offset(1, 0)
r = mrow.Row '找到最后一行数据的行数
rd = r - 1
'单元格引用方法Worksheets(1).Cells(1, 1).Value = 24
'使用for 循环来取得schedule中日期,在日历中找到相同的日期在其对应的单元格写入试验数据
For j = 6 To 7
For i = 20 To rd
mdate = Workbooks("RT 收件登录表 new2.xls").Worksheets("schedule").Cells(i, j).Value
ndate = Workbooks("RT 收件登录表 new2.xls").Worksheets("schedule").Cells(i, j).Value
If mdate > 40000 And mdate < 50000 Then
' r = Sheets.Count
' For m = 1 To r
'' with
'' If mdate >= 40299 And mdate < 40330 Then
' With Worksheets(m).Range("a1:ca1")
'' Set col = .Find(mdate, LookIn:=xlValues)
'' If Not col Is Nothing Then
'' 'datecolumn = col.Column
'' firstAddress2 = col.Address
'' Set ddd = col.Offset(daterow - 1, 0)
'' q1 = ddd.Address
'' qqq = ddd.Column
'' Do
'' Set col = .FindNext(col)
'' Loop While Not col Is Nothing And col.Address <> firstAddress2
'' 'ddd.Value = ddd.Value & "!" & Worksheets("schedule").Cells(i, 2).Value & " " & Worksheets("schedule").Cells(i, 3).Value & " " & Worksheets("schedule").Cells(i, 4).Value & " " & Worksheets("schedule").Cells(19, j).Value
'' End If
' Exit For
'
'
' End With
'
'
'
'
' Next
'判断是否为SAT
tp2 = Workbooks("RT 收件登录表 new2.xls").Worksheets("schedule").Cells(i, 4).Value
If Right(Workbooks("RT 收件登录表 new2.xls").Worksheets("schedule").Cells(i, 4).Value, 3) = "SAT" Then
'写入SAT数据表
scount = Workbooks("2010 SAT list.xls").Sheets.Count
For n = 1 To scount
With Workbooks("2010 SAT list.xls").Worksheets(n).Range("b1:ca1")
Set satcol1 = .Find(ndate, LookIn:=xlValues)
If Not satcol1 Is Nothing Then
'datecolumn = col.Column
firstAddress3 = satcol1.Address
Set satddd = satcol1.Offset(daterow - 1, 0)
'qqq = ddd.Column
Do
Set satcol1 = .FindNext(satcol1)
Loop While Not satcol1 Is Nothing And satcol1.Address <> firstAddress3