vb在excel中查找并赋值,加分
在a.xls中查找Text1中的内容,比如说查找到的格子是(3,1)或者(12,2)现在在(3.3)写入1,总之就是在查找到得单元格所在行的第三列写入1...
在a.xls中查找Text1中的内容,比如说查找到的格子是(3,1)或者(12,2)现在在(3.3)写入1,总之就是在查找到得单元格所在行的第三列写入1
展开
2个回答
展开全部
首先工程中引用 EXCEL 对象
dim excelApp as excel.application
dim BK as excel.workbook
dim Sht as excel.worksheet
dim rng
dim i as long
set excelapp=createobject("excel.application")
set bk=excel.open("C:\AAA\a.xls")
for i=1 to bk.worksheets.count
set sht=bk.worksheets(i)
for each rng in sht.usedrange
if rng.value=me.text1 then
sht.cells(rng.row,3)=1
end if
next
for
next
bk.save
bk.close
excelapp.quit
set rng=nothing
set sht=nothing
set wb=nothing
set excelapp=nothing
dim excelApp as excel.application
dim BK as excel.workbook
dim Sht as excel.worksheet
dim rng
dim i as long
set excelapp=createobject("excel.application")
set bk=excel.open("C:\AAA\a.xls")
for i=1 to bk.worksheets.count
set sht=bk.worksheets(i)
for each rng in sht.usedrange
if rng.value=me.text1 then
sht.cells(rng.row,3)=1
end if
next
for
next
bk.save
bk.close
excelapp.quit
set rng=nothing
set sht=nothing
set wb=nothing
set excelapp=nothing
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
为什么非得VB
VBA行吗???
VBA 代码
Sub MainFun()
Dim rng As Range, cel As Range
Set rng = Sheet2.Range("A1:Z1000")
Set cel = GetCel(rng, "text1")
If Not cel Is Nothing Then
cel.Offset(0, 2).Value = 1
End If
End Sub
Function GetCel(rng As Range, temp As String) As Range
On Error GoTo L_end
Set GetCel = rng.Find(temp, LookIn:=xlValues, lookat:=xlWhole)
Exit Function
L_end:
Set GetCel = Nothing
End Function
VBA行吗???
VBA 代码
Sub MainFun()
Dim rng As Range, cel As Range
Set rng = Sheet2.Range("A1:Z1000")
Set cel = GetCel(rng, "text1")
If Not cel Is Nothing Then
cel.Offset(0, 2).Value = 1
End If
End Sub
Function GetCel(rng As Range, temp As String) As Range
On Error GoTo L_end
Set GetCel = rng.Find(temp, LookIn:=xlValues, lookat:=xlWhole)
Exit Function
L_end:
Set GetCel = Nothing
End Function
本回答被网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询