Consulting

Results 1 to 4 of 4

Thread: Solved: where am i going wrong?

  1. #1

    Solved: where am i going wrong?

    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

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


    [VBA]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[/VBA]

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

  2. #2
    VBAX Sage
    Joined
    Apr 2007
    Location
    United States
    Posts
    8,728
    Location
    Not necessary to Select things

    I'd probably try something like this

    [vba]
    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
    [/vba]

    Paul

  3. #3
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    Maybe this

    [vba]

    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
    [/vba]
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  4. #4
    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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •