|
楼主 |
发表于 2018-1-28 19:27
|
显示全部楼层
感谢老师的指教!你的方法可行。而我自已常试把复制的次序倒过来也可行,把数值必不相司的单元先行复制,当然我基础薄弱是一定的了,哈哈!那原来的问题就是因为地址写错造成的吗,还是判断的情况都是呢?
下面还有一个代码请教老师您的:
数据关系:
触发单元格为(H9),条件项为(K2),当(K2)值(=0)时才会触发复制,分别与(AG2,AG3,AG4)内容作为查找对象。举例:在(D2:D7)单元格中查到与(AG3)相同的数值,得出(000550)这个数值在(D列)中的行号(目前是在第(4)行,但下次就会变动行号或者消失的),以此行号(4)为基础,在(H列)对应(此行号+1行),(也就是H4加一行,变为H5单元格并把(AI3)的数值复制进(H5)格内)。 本表VBA代码遇到的问题:
多次调试都出现定义不正确,查找方式错误等情况。
_试算表- (恢复的).zip
(29.46 KB, 下载次数: 1)
'Private Sub Worksheet_Change(ByVal Target As Range)
'If Target.Count > 1 Then Exit Sub
'If Target.Column <> 8 Then Exit Sub
' If Target.Row = 9 Then
' If Range("k2") > 0 Then
' End If
' End If
'For Each Rng In Range("d2:d7")
' If Rng = Range("AG3") Then
' a = Rng.Row
' End If
'Next
'MsgBox "行号为" & a & "-" & "列号为" & b
'End Sub
Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Count > 1 Then Exit Sub
If Target.Column <> 8 Then Exit Sub
If Target.Row = 9 Then
If Range("k2") > 0 Then
End If
End If
'Dim findcell%
'Dim fr%
'Set findcell = Range("d2:d7").Find(Range("AG3").Value)
'Set findcell = Columns("d2:d7").Find("00550", LookIn:=xlValues, lookat:=xlWhole).Row
'If Not findcell Is Nothing Then
'fr = findcell.Row
Dim rng As Range, rngSearch As Range
Dim vl As String
Set rng = Range("d2:d7")
vl = "00550"
Set rngSearch = rng.Find(vl)
If Not rngSearch Is Nothing Then
r = rngSearch.Row
Cells(r, 8) = Cells(3, 35).Value
End If
End Sub
'e = Columns(2).Find("60", SearchDirection:=2).Row
'Set findcell = Columns("c").Find("宁波", LookAt:=xlPart)
'If Not findcell Is Nothing Then
|
|