Consulting

Results 1 to 4 of 4

Thread: Copy to a specific cell

  1. #1

    Copy to a specific cell

    Hello folks. This is my first time posting here as Im in a bind at work and need to get a quick macro done.

    So I need to copy a line from one spreedsheet to another spreadsheet in the same workbook. I used the record feature and got this:

    [vba]Sub Glycine()
    '
    ' Glycine Macro
    '
    '
    ActiveWindow.SmallScroll Down:=-6
    ActiveCell.Range("A1:G1").Select
    Selection.Copy
    ActiveWindow.SmallScroll Down:=-3
    Sheets("Purchase Order").Select
    ActiveSheet.Paste
    End Sub[/vba]

    What I need is the ability to paste it to a specific cell in the Purchase Order sheet, cell B3. However, if B3 is occupied with text I then need it to copy to B4 and so on to B5 all the way to B18.

    Im hoping someone can help me. Thank you so much!
    -Tim

  2. #2
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    [vba]
    Sub Glycine()
    '
    ' Glycine Macro
    '
    With Sheets("Purchase Order")

    ActiveSheet.Range("A1:G1").Copy .Cells.Rows.Count,"B").End(xlUp).Offset(1, 0)
    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

  3. #3
    VBAX Mentor
    Joined
    Dec 2008
    Posts
    404
    Location
    ...Or

    [vba]Sub Glycine_1()
    Dim FirstEmptyCell As Range
    Dim a As Integer

    With Worksheets("Purchase Order")
    a = Application.WorksheetFunction.CountA(.Range("B3:B18"))

    If a > 15 Then
    MsgBox "Range B3:B18 in """ & .Name & """ is full!", vbExclamation
    Exit Sub
    End If

    Set FirstEmptyCell = .Range("B3").Offset(a)
    End With

    ActiveCell.Resize(, 7).Copy FirstEmptyCell

    Set FirstEmptyCell = Nothing
    End Sub[/vba]

    Artik

  4. #4
    Worked beautifully. Thank you for the quick reply!

Posting Permissions

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