0

I had posted something similar earlier, thought I had it, and deleted my post. Ugh. So, here's what I'm trying to accomplish:

  • If the variables are equal c = d (comparing two loops), then locate the correct d value location (column/row) on the sheet
  • Copy the d value from the cell into a specified range on another sheet .end(xlup).offset(1,0) ----this works fine
  • Copy the adjacent cell value a few rows from the d value (offset 0,-16)

I can't get the offset value correctly. It's giving me the range1 R3 value instead.

suggestions?

example:

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

Final Code:

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

The root of the issue is that once the value/position of w is identified, I need to grab the offset(0,-16) from that cell and put that in "O". I've tried a few different ways, but I'm just not seeing it... ugh. Help please!

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 に答える