在VB6.0+ Excel 中,如何判断某一数据在数据表中的位置?
例如,在数据表中某一个单元格数据为“MON”,如何判断他的位置?
你应该直接@大神啊,不能在这里干等着
Private Sub Command1_Click()
Dim Xlbook As Workbook
Dim Xlapp As Application
Dim Xlsheet As Worksheet
Set Xlapp = CreateObject("Excel.Application") '隐藏方式打开excel
Set Xlbook = Xlapp.Workbooks.Open("D:\123.xls") '打开工作簿
Set Xlsheet = Xlbook.Worksheets(1) '让xlsheet代表第一个表
Print Xlsheet.Range("A1") '取数据什么的跟VBA一样的。
Xlbook.Close False '关闭工作簿 不保存
Set Xlapp = Nothing '释放
Set Xlbook = Nothing
End Sub
'
Range("A1").Select
Dim targetRange As Range
Set targetRange = Cells.Find(What:="MONx", After:=ActiveCell, LookIn:=xlFormulas, LookAt:= _
xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:=False _
, MatchByte:=False, SearchFormat:=False)
If targetRange Is Nothing Then
Debug.Print "not found"
Else
Debug.Print targetRange.Row
Debug.Print targetRange.Column
Cells.FindNext(After:=ActiveCell).Activate
End If
'targetRange.Activate
'What =>改成你要查的字符
Range("A1").Select
Dim targetRange As Range
Set targetRange = Cells.Find(What:="MON", After:=ActiveCell, LookIn:=xlFormulas, LookAt:= _
xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:=False _
, MatchByte:=False, SearchFormat:=False)
If targetRange Is Nothing Then
Debug.Print "not found"
Else
Debug.Print targetRange.Row
Debug.Print targetRange.Column
Cells.FindNext(After:=ActiveCell).Activate
End If
'targetRange.Activate