excel - 在某些单元格中循环的宏
问题描述
我正在将某些值从 Sheet3 复制到 Sheet2 并且我有一个循环,问题是我只想在单元格中循环。基本上,如果我在 Sheet2 的 D 列中有值 1、2、3、4 等,我只想在包含数字“1”的 H 列行中循环。到目前为止,这是我的代码。
Sub rand_v2()
Dim RNG1 As Range, RNG2 As Range, r As Range, p As Range, d As Collection, N As Long, MLRow As Long, x As Long
Set RNG1 = Sheet3.Range("A2:A500")
MLRow = Sheet2.Range("B" & Rows.Count).End(xlUp).Row
For x = 4 To MLRow
If Sheet2.Cells(x, 8).Value = vbNullString Then
Set d = New Collection
For Each r In RNG1
If r.Value <> vbNullString And Sheet3.Cells(r.Row, 4).Value = Sheet2.Cells(x, 2).Value And r.Value <> Sheet2.Cells(x - 1, 8).Value And r.Value <> Sheet2.Cells(x - 2, 8).Value And r.Value <> Sheet2.Cells(x - 3, 8).Value Then
d.Add r
N = Application.WorksheetFunction.RandBetween(1, d.Count)
d.Item(N).Copy
Sheet2.Cells(x, 8).PasteSpecial xlPasteValues
End If
Next r
Set d = Nothing
End If
Next x
End Sub
解决方案
推荐阅读
- twilio - 将 twilio flex 实时呼叫转移到另一个号码
- sql-server - 查找不是 utf8 的表?
- python - How to fix 'TypeError: expecting string or bytes object' error in Python
- php - 使用上一个/下一个按钮将整数插入我的表的最佳方法
- machine-learning - 经过大量训练后,神经网络的适应速度会变慢吗?
- javascript - 从站点自动安装扩展?
- python - 使用 activate_this 激活 venv 时无法导入 numpy
- sql-server - 使用 FOR XML PATH 连接字符串
- c++ - 当我不应该有该类的容器时如何从继承的类中存储对象
- git - "git diff-index --name-only HEAD" 报告windows下的文件,而不是cygwin下的