总而言之,我在理解为什么出现对象错误时遇到了极大的麻烦。每次阅读某些内容时,我都会认为该内容已经弄明白了,而当我尝试实现它时,我会得到一个错误。我现在正在使用的特定代码是:
'Set station cell value
iRow = rEmptyStation.Row
iColumn = rEmptyStation.Column
Cells(iRow - 1, iColumn).Copy
Range(Cells(iRow, iColumn), Cells(iRow, iColumn)).Select
Selection.Paste
rEmptyStation.Value = sStation
iRow
并且iColumn
是long类型,rEmptyStation
一个范围和sStation
一个字符串。我要做的就是将单元格复制到所讨论的单元格上方,将其粘贴到所讨论的单元格中(因为它正在格式化),然后将所讨论的单元格设置为等于字符串。
它在我所在的行上给了我一个对象错误[junk].Select
。代替[junk]
,我尝试了put Cells(iRow, iColumn)
,我尝试了使用With Worksheets(1)
and.Cells(iRow, iColumn)
语句,并且我也尝试了在语句中使用.Cells()
and 。.Range()
With
任何人都可以向我解释如何使其正常工作,以及如何在每种情况下选择正确的代码吗????
最终对我有用的是将我的代码切换到以下代码:
'Set station cell value
iRow = rEmptyStation.Row
iColumn = rEmptyStation.Column
Cells(iRow - 1, iColumn).Copy
Cells(iRow, iColumn).Select
Selection.PasteSpecial xlPasteFormats
rEmptyStation.Value = sStation
现在,我不知道为什么,但是当我有以下代码时,出现了对象错误(在该Selection.Paste
行):
'Set station cell value
iRow = rEmptyStation.Row
iColumn = rEmptyStation.Column
Cells(iRow - 1, iColumn).Copy
Cells(iRow, iColumn).Select
Selection.Paste
rEmptyStation.Value = sStation
这是我项目的完整链接。如果有人能弄清楚,那就太好了(该代码段之后的代码未经过测试!)。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句