Problem moving Excel ranges in VB6

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • sotsigo
    New Member
    • Mar 2007
    • 3

    Problem moving Excel ranges in VB6

    Hi there,
    I am a quite unexperienced VB user and I am trying to do some simple operations in excel. I am presenting my existing problematic code below.

    I am trying to copy/paste a range of values (two columns, S7:T101) from a sheet(INTERACTI ON-RF_Calc) in a different sheet (RF-Calculation). In the destiantion sheet a calculation will take place for which the result will be created in cell (H13). Now I need to copy/pasted this results back the original sheet (INTERACTION-RF_Calc) in a column next to the original input range values. Obviously I need to do this for the whole lenght of the column.

    The code below is only able to do the requested operation for the first set of values.

    I would appreciate a little bit of help.

    Thanks for your time.





    Code:
    Sub Rx3Ry()
    '
    ' Rx3Ry Macro
    ' Macro recorded 28.02.2007 by sotsigo
    '
    Dim d As Integer
    
    For d = 1 To 10
    
        Range("S7:T101").Select
        Selection.Copy
        Sheets("INTERACTION-RF_Calc").Select
        Range("J2:K2").Select
        Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
            :=False, Transpose:=False
        Range("H13").Select
        'Application.CutCopyMode = False
        Selection.Copy
        Sheets("RF-Calculation").Select
        Range("U7").Select
        Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
            :=False, Transpose:=False
         
    Next d
    End Sub
    Last edited by willakawill; Mar 2 '07, 04:55 PM. Reason: please use code tags when posting code
  • willakawill
    Top Contributor
    • Oct 2006
    • 1646

    #2
    Hi. please point out in your code where it does not work. Thanks

    Comment

    • Killer42
      Recognized Expert Expert
      • Oct 2006
      • 8429

      #3
      Yes, I think the main question is - which part of the operation only works for the first value? Copying it over, doing the calculations, or copying the results back?

      In fact, your original question is a little confusing. You basically say that you copy across a range, then do a calculation which produces a single result (H13) then you want to copy that one result back to a range of positions? Is that right?

      Comment

      • sotsigo
        New Member
        • Mar 2007
        • 3

        #4
        Originally posted by Killer42
        Yes, I think the main question is - which part of the operation only works for the first value? Copying it over, doing the calculations, or copying the results back?

        In fact, your original question is a little confusing. You basically say that you copy across a range, then do a calculation which produces a single result (H13) then you want to copy that one result back to a range of positions? Is that right?
        Hi,
        The code works only for the first value of the column and it's doing everything correctly: copying the input at the destination cells, getting the result from the single H13 cell and copying it back to the original sheet at a cell next to the input cell.

        The problem of the code is that it's not able to carry out the operation for the full range of the data in the input column.

        Just to make it a bit easier, the code is not copying a range (and thats exactly the problem!). It only copies the first valuue of the range. I believe that i need to incorporate a loop into the code but i am not sure how to do this.

        I hope it's clear now

        Comment

        • sotsigo
          New Member
          • Mar 2007
          • 3

          #5
          Originally posted by willakawill
          Hi. please point out in your code where it does not work. Thanks
          Hi!
          The code works only for the first range of values. I believe it requires a loop but I am not sure how to built it!

          Thanks for your time!

          Comment

          • Killer42
            Recognized Expert Expert
            • Oct 2006
            • 8429

            #6
            Let's tackle one thing at a time. Although I haven't checked this, I suspect the reason it's only copying one value is the line Range("J2:K2"). Select. Perhaps if you change this to Range("J2").Sel ect it will allow the whole range to be copied.

            (I've changed the subject if the thread, to make it more useful for those searching the forum.)

            Comment

            Working...