如何解决将某些值复制到定义的工作表中的不同位置
我正在处理一个宏,该宏将工作簿的第3张纸中的H2值作为值并将其复制到A列中包含单词“ page”的行的第5行中最后使用的列后面的列中一个名为“概述”的工作表,但前提是H2中的值不为0。之后,我需要在该值所发布到的同一列的第4行中添加一个字符串。有人可以帮助我让我的代码正常工作吗?我特别喜欢复制值。这就是我到目前为止所拥有的:
'
' example Macro
'
'
Dim cRange As Range
Dim valuessendmemore As Range
Dim Cell As Range
Dim wsDestination As Worksheet,wsSource As Worksheet
'set worksheets
With ThisWorkbook
Set wsSource = .Worksheets(3)
Set wsDestination = .Worksheets("Overview")
End With
LastColumn1 = wsDestination.Cells(5,wsDestination.Columns.Count).End(xlToLeft).Column
Set cRange = wsSource.Range("H2")
For Each Cell In cRange
If Cell.Value > 0 Then
Cell.Value.Copy
'Set the value you want to search
strSearch = "*Page*"
'Set the column you want to seach
ColumnNo = 1
'Create a with statement to point Sheet1.
With wsDestination
'Search for strSearch in column number ColumnNo
Set rngFound = .Columns(ColumnNo).Find(strSearch,LookIn:=xlValues,lookat:=xlWhole)
If Not rngFound Is Nothing Then
'Paste row
wsDestination.Range(LastColumn1 & rngFound.Row).PasteSpecial Paste:=xlPasteValues
'Delete row
End If
End With
End If
Next Cell
Application.CutCopyMode = False
End Sub
解决方法
毫无疑问,您的问题出在此声明Range(LastColumn1 & rngFound.Row)
上。假设您的LastColumn1
评估为25,而rngFound.Row
评估为1000。现在您的语句说Range(251000)
不存在。正确的重写应为:
wsDestination.Cells(rngFound.Row,LastColumn1)...
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。