PDA

View Full Version : Solved: where am i going wrong?



stramvaier
07-29-2011, 03:10 AM
my problem is as follows:
i have a commandbutton in my sheet.
i want it to allways copy the info in cell A1 to next sheet, but also let the user select select a row in my sheet that is going to be copied also. that row can vary between 50 different rows, but just one each time the button is pressed.
here is what i tried so far,but i cant seem to get it to work:eek:

i think what i struggle with is to declare the correct memory and the correct notation that tells what it is.


Sub CommandButton1_click()

Dim minne1 As String

minne1 = Rows.userdefined.Select


Sheets("Kjøling").Select
Range("minne1").Select
Selection.Copy
Sheets("Sammenligning").Select
Range("A4").Select
ActiveSheet.Paste
Sheets("Kjøling").Select

Range("A1").Select
Selection.Copy
Sheets("Sammenligning").Select
Range("A3").Select
ActiveSheet.Paste
Sheets("Kjøling").Select

End Sub

Any help is greatly appreciated.im new to this and learning everyday so pleace dont kill me for beeing stupid:help

Paul_Hossler
07-31-2011, 07:40 PM
Not necessary to Select things

I'd probably try something like this


Sub CommandButton1_click()

'is a Range is not selected (e.g. Textbox) then get out
If Not TypeOf Selection Is Range Then Exit Sub

'assume Sheet1 is active and has the command button
'copy the first row in the selection and paste it to sheet2, A4
Call Selection.Cells(1, 1).EntireRow.Copy(Worksheets("Sheet2").Range("A4"))

'copy A1 to sheet2, A3
Call ActiveSheet.Range("A1").Copy(Worksheets("Sheet2").Range("A3"))

End Sub


Paul

Bob Phillips
08-01-2011, 12:37 AM
Maybe this



Sub CommandButton1_click()
Dim rng As Range

Set rng = Application.InputBox("Select a cell in the target range to copy with the mouse", Type:=8)

With Selection.EntireRow

.Copy Worksheets("Kjøling").Range("A4")
.Copy Worksheets("Sammenligning").Range("A3")
End With
End Sub

stramvaier
08-01-2011, 03:57 AM
Thank you Paul. your code solved my problem. it now runs as i want it to. Now i only need too understand it, but thanks again :beerchug: