0

我之前发布过类似的东西,以为我有它,然后删除了我的帖子。啊。所以,这就是我想要完成的事情:

  • 如果变量相等 c = d(比较两个循环),则在工作表上找到正确的 d 值位置(列/行)
  • 将单元格中的 d 值复制到另一张纸上的指定范围内 .end(xlup).offset(1,0) ----这很好用
  • 从 d 值复制相邻的单元格值几行(偏移量 0,-16)

我无法正确获得偏移值。它给了我 range1 R3 值。

建议?

例子:

Set range1 = wbk1.Worksheets(1).Range(R3:R20)
Set range2 = wbk2.worksheets(2).Range("N" & .Rows.Count).End(xlup).Offset(1,0)
Set range3 = wbk2.worksheets(2).Range("O" & .Rows.Count).End(xlup).Offset(1,0)
Set range4 = range1.Offset(0,-16)
For Each c in g.keys
     For Each d in range1 
          If c = d Then 
               range2.Value = d  
               range3.value = range4.value  (this isn't working)
          End If
     Next d
Next c

最终代码:

Set rngchassIP = wbkJackPot.Worksheets(1).Range("R3:R30") 
Set rngchassCS = wbkVer.Worksheets("Cutsheets").Range("M2:M5")
Set rngchassyver = wbkVer.Worksheets("Cutsheets").Range("N" & .Rows.Count).End(xlUp).Offset(1, 0)
Set rngchassypst = wbkVer.Worksheets("Cutsheets").Range("O" & .Rows.Count).End(xlUp).Offset(1, 0)


For Each c In rngchassCS               
    For Each w In rngchassIP           
        If c = w Then                   
            rngchassyver.Value = w      
            rngchassypst.Value = w.Offset(0, -16)
        End If
    Next w
Next c

问题的根源在于,一旦确定了 w 的值/位置,我需要从该单元格中获取偏移量(0,-16)并将其放在“O”中。我尝试了几种不同的方法,但我只是没有看到它......呃。请帮忙!

4

1 回答 1

1

只是猜测你想在这里做什么......

Set range1 = wbk1.Worksheets(1).Range("R3:R20")

'are range 2 and 3 on the same row?
Set range2 = wbk2.worksheets(2).Range("N" & .Rows.Count).End(xlup).Offset(1,0)
Set range3 = wbk2.worksheets(2).Range("O" & .Rows.Count).End(xlup).Offset(1,0)

For Each c in g.keys
     For Each d in range1.Cells 
          If c = d Then 
               range2.Value = d  
               range3.value = d.Offset(0,-16)
               'What now?  Once one match has been found,
               '  any later matches will write to the same cells...
          End If
     Next d
Next c
于 2013-01-28T07:07:03.160 回答