方法'Range'作用于对象'_WorkSheet'时失败???

caprason 2008-12-09 11:22:52
      If xlSheet.Range(Lines1 & Rows1).vlaue = "●" And xlSheet.Range(Lines2 & Rows1).vlaue = "●" And xlSheet.Range(Lines3 & Rows1).vlaue = "●" And xlSheet.Range(Lines4 & Rows1).vlaue = "●" And xlSheet.Range(Lines5 & Rows1).vlaue = "●" Then
xlSheet.Cells(Lines1, Rows1).Interior.ColorIndex = 6
End If


哪位大哥帮忙改一下啊?运行报错“方法'Range'作用于对象'_WorkSheet'时失败 ”
...全文
1640 11 打赏 收藏 转发到动态 举报
写回复
用AI写文章
11 条回复
切换为时间正序
请发表友善的回复…
发表回复
神马都能聊 2008-12-10
  • 打赏
  • 举报
回复

If xlSheet.cells(Lines1 & Rows1) = "●" And xlSheet.cells(Lines2 & Rows1) = "●" And xlSheet.cells(Lines3 & Rows1) = "●" And xlSheet.cells(Lines4 & Rows1) = "●" And xlSheet.cells(Lines5 & Rows1) = "●" Then
xlSheet.Cells(Lines1, Rows1).Interior.ColorIndex = 6
End If
caofusheng 2008-12-10
  • 打赏
  • 举报
回复
xlSheet对象建了吗?
caprason 2008-12-10
  • 打赏
  • 举报
回复
感谢jhone99
代码简化如下:
  For R = 2 To 34    
Do
L = 3
If xlSheet.Cells(L, R) = "●" And xlSheet.Cells(L + 1, R) = "●" Then
xlSheet.Cells(L, R).Interior.ColorIndex = 6
End If
L = L + 1
Loop Until xlSheet.Range("A" & L).Value = ""

Next R
caprason 2008-12-10
  • 打赏
  • 举报
回复
回楼上的,想不出来怎么处理,所以定义了很多变量
jhone99 2008-12-10
  • 打赏
  • 举报
回复
[Quote=引用 7 楼 caprason 的回复:]
回2楼的:对象建立了。
3楼的代码:应用程序定义或对象定义错误
回lyserver的:lines1、2、3、4、5和rows1都是变量

VB codeDim xlApp As New Excel.Application
Dim xlBook As New Excel.Workbook
Dim xlSheet As New Excel.Worksheet
Dim N As Long
Dim Rows1 As Long
Dim Rows2 As Long
Dim Rows3 As Long
Dim Rows4 As Long
Dim Rows5 As Long
Dim Rows6 As Long
Dim Rows7 As Long
Dim Lines1 As Long
D…
[/Quote]

用循环或数组,怎么用了这么多变量,太kechen
duyin2004 2008-12-10
  • 打赏
  • 举报
回复
xlSheet对象没有没有引用吧
caprason 2008-12-10
  • 打赏
  • 举报
回复
回2楼的:对象建立了。
3楼的代码:应用程序定义或对象定义错误
回lyserver的:lines1、2、3、4、5和rows1都是变量
Dim xlApp As New Excel.Application
Dim xlBook As New Excel.Workbook
Dim xlSheet As New Excel.Worksheet
Dim N As Long
Dim Rows1 As Long
Dim Rows2 As Long
Dim Rows3 As Long
Dim Rows4 As Long
Dim Rows5 As Long
Dim Rows6 As Long
Dim Rows7 As Long
Dim Lines1 As Long
Dim Lines2 As Long
Dim Lines3 As Long
Dim Lines4 As Long
Dim Lines5 As Long

If Text1.Text = "" Then
MsgBox ("请选择文件位置!")
Exit Sub
Else
Set xlBook = xlApp.Workbooks.Open(Text1.Text)
Set xlSheet = xlBook.Worksheets(2)
End If
Lines1 = 1
Lines2 = 2
Lines3 = 3
Lines4 = 4
lings5 = 5
Rows1 = 1
Rows2 = 2
Rows3 = 3
Rows4 = 4
Rows5 = 5
Rows6 = 6
Rows7 = 7
Do
Lines1 = Lines1 + 1
Lines2 = Lines2 + 1
Lines3 = Lines3 + 1
Lines4 = Lines4 + 1
lings5 = Lines5 + 1
Rows1 = Rows1 + 1
Rows2 = Rows2 + 1
Rows3 = Rows3 + 1
Rows4 = Rows4 + 1
Rows5 = Rows5 + 1
Rows6 = Rows6 + 1
Rows7 = Rows7 + 1
If xlSheet.Range(Lines1 & Rows1).vlaue = "●" And xlSheet.Range(Lines2 & Rows1).vlaue = "●" And xlSheet.Range(Lines3 & Rows1).vlaue = "●" And xlSheet.Range(Lines4 & Rows1).vlaue = "●" And xlSheet.Range(Lines5 & Rows1).vlaue = "●" Then
xlSheet.Cells(Lines1, Rows1).Interior.ColorIndex = 6
End If
Loop Until xlSheet.Range("A" & j + 1).Value = ""
lyserver 2008-12-10
  • 打赏
  • 举报
回复
破CSDN,发了几次发不上,结果又发多了。
lyserver 2008-12-10
  • 打赏
  • 举报
回复
'代码一:
If xlSheet.Cells(1, 1) = "●" And xlSheet.Cells(2, 1) = "●" And xlSheet.Cells(3, 1) = "●" And xlSheet.Cells(4, 1) = "●" And xlSheet.Cells(5, 1) = "●" Then
xlSheet.Cells(lines1, Rows1).Interior.ColorIndex = 6
End If
'代码二:
If xlSheet.Range("A1") = "●" And xlSheet.Range("A2") = "●" And xlSheet.Range("A3") = "●" And xlSheet.Range("A4") = "●" And xlSheet.Range("A5") = "●" Then
xlSheet.Cells(lines1, Rows1).Interior.ColorIndex = 6
End If
'代码三:
Dim v
v = xlSheet.Range("A1", "A5").Value
If v(1, 1) = "●" And v(2, 1) = "●" And v(3, 1) = "●" And v(4, 1) = "●" And v(5, 1) = "●" Then
xlSheet.Cells(lines1, Rows1).Interior.ColorIndex = 6
End If
lyserver 2008-12-10
  • 打赏
  • 举报
回复
'代码一:
If xlSheet.Cells(1, 1) = "●" And xlSheet.Cells(2, 1) = "●" And xlSheet.Cells(3, 1) = "●" And xlSheet.Cells(4, 1) = "●" And xlSheet.Cells(5, 1) = "●" Then
xlSheet.Cells(lines1, Rows1).Interior.ColorIndex = 6
End If
'代码二:
If xlSheet.Range("A1") = "●" And xlSheet.Range("A2") = "●" And xlSheet.Range("A3") = "●" And xlSheet.Range("A4") = "●" And xlSheet.Range("A5") = "●" Then
xlSheet.Cells(lines1, Rows1).Interior.ColorIndex = 6
End If
'代码三:
Dim v
v = xlSheet.Range("A1", "A5").Value
If v(1, 1) = "●" And v(2, 1) = "●" And v(3, 1) = "●" And v(4, 1) = "●" And v(5, 1) = "●" Then
xlSheet.Cells(lines1, Rows1).Interior.ColorIndex = 6
End If
lyserver 2008-12-10
  • 打赏
  • 举报
回复
'代码一:
If xlSheet.Cells(1, 1) = "●" And xlSheet.Cells(2, 1) = "●" And xlSheet.Cells(3, 1) = "●" And xlSheet.Cells(4, 1) = "●" And xlSheet.Cells(5, 1) = "●" Then
xlSheet.Cells(lines1, Rows1).Interior.ColorIndex = 6
End If
'代码二:
If xlSheet.Range("A1") = "●" And xlSheet.Range("A2") = "●" And xlSheet.Range("A3") = "●" And xlSheet.Range("A4") = "●" And xlSheet.Range("A5") = "●" Then
xlSheet.Cells(lines1, Rows1).Interior.ColorIndex = 6
End If
'代码三:
Dim v
v = xlSheet.Range("A1", "A5").Value
If v(1, 1) = "●" And v(2, 1) = "●" And v(3, 1) = "●" And v(4, 1) = "●" And v(5, 1) = "●" Then
xlSheet.Cells(lines1, Rows1).Interior.ColorIndex = 6
End If

7,763

社区成员

发帖
与我相关
我的任务
社区描述
VB 基础类
社区管理员
  • VB基础类社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧