本人VB6小白,最近需要帮好友写一个工具,代码也是copy的,但是不知道问题在哪?__续
之前发过一个帖子,蒙 风吹过b 大哥启示,仍无头绪,现在我贴出自己的不完整代码,忘各位大虾帮帮忙瞅瞅,现在主要的问题是我知道了如何读取单元格的数据,但是如何让这个数据在另外一个excel表格工作簿搜索,并找到一样的单元格,然后拷贝这个单元格一行上的信息,谢谢各位大侠。。。。Private Sub Command1_Click()
If Text1.Text = "" Or Text2.Text = "" Or Text3.Text = "" Then
MsgBox "文件名不能为空!", vbCritical, "出错"
Exit Sub
End If
If Dir(Text2.Text) <> "" Then
i = MsgBox("文件存在,是否覆盖?", vbYesNo + vbQuestion, "保存")
If i = vbYes Then
Kill Text2.Text
Else
Exit Sub
End If
End If
Command1.Enabled = False
Command2.Enabled = False
Command3.Enabled = False
Command4.Enabled = False
Set xl = CreateObject("Excel.Application")
Set X2 = CreateObject("Excel.Application")
'xl.Visible = True
xl.Workbooks.Open Text1.Text
X2.Workbooks.Open Text3.Text
Set sheet1 = xl.Workbooks(1).Worksheets(1) '数据来源表
Set wk2 = X2.Workbooks(2) '目的数据表
tmp_s = sheet1.Range("A1")
If tmp_s <> "元件分类" Then
MsgBox "该BOM非原始PCB导出的BOM", vbCritical, "出错"
GoTo wk
End If
fullnum = sheet1.UsedRange.Rows.Count + 1
row = 2:
Do While True
'seq_s = sheet1.Range("C" & row)
'If seq_s = "" Then Exit Do
seq_s = sheet1.Range("C" & row)
If seq_s = "" Then GoTo ctt
top_s = sheet1.Range("H" & row)
ctt: row = row + 1
DoEvents
Label3.Caption = "处理进度:" & ((row - 2) * 100 \ (fullnum - 2)) & "%"
Loop
End Sub
MsgBox "处理完成", vbInformation, "完成"
Label3.Caption = ""
xl.Workbooks(2).SaveAs Text2.Text
wk:
xl.Workbooks(2).Close savechanges:=False
xl.Workbooks(1).Close savechanges:=False
Set sheet1 = Nothing
Set wk2 = Nothing
Set xl = Nothing
Command1.Enabled = True
Command2.Enabled = True
Command3.Enabled = True
Command4.Enabled = True
End Sub