0
votes

Im trying to create a function in VBA that copies data from one sheet to another based on the input to the function. However, I'm having great difficulty in using the arguments to the function in the actual function itself.

Below is my code: as you can see, the range I want is hardcoded in for now, and this works! But I cannot get it to accept the range I pass as an argument to the function. What am I doing wrong?

data should be in place of range(F35:F65) and target should be in place of range(C6)

Function Copytranspose(data As Range, target As Range)

    
    
    Worksheets("Data").Activate
    ActiveSheet.Range("F35:F65").Copy
    
    Worksheets("Totalizers").Activate
    ActiveSheet.Range("C6").PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
        :=False, Transpose:=False

        
End Function

Sub tempo()
Call Copytranspose(Range("F35:F65"), Range("C6"))

End Sub

You dont seem to be using the arguments, you are passing in the args and they are also hard coded. It would be data.copy and target.pastespecial. Or target.resize(data.rows.count,data.columns.count).value=data.valueNathan_Sav
You should also add sheet references to your arguments, and no need to activate/select things.SJR