Consulting

Page 1 of 2 1 2 LastLast
Results 1 to 20 of 26

Thread: copy and paste active cell down a column

  1. #1
    VBAX Regular
    Joined
    Jul 2007
    Posts
    78
    Location

    copy and paste active cell down a column

    I like to create a macro that can automate the process of copying the active cell downward as long as the column D is not empty bearing in mind that there maybe empty rows in column D. It has to be intelligent enoug to skip empty rows.

  2. #2
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    [vba]

    ActiveCell.Copy Activecell.Resize(Cells(Rows.Count,"D").End(xlUp).Row)
    [/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 Regular
    Joined
    Jul 2007
    Posts
    78
    Location
    The macro is copying down as what I want to but I did not make it clear enough that if cell in column D is empty the corresponding cell in the active column should also be empty.

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

    [vba]

    With ActiveCell

    .Offset(1, 0).Resize(Cells(Rows.Count, "D").End(xlUp).Row).FormulaR1C1 = _
    "=IF(RC4="""","""",R" & .Row & "C)"
    End With
    [/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

  5. #5
    VBAX Regular
    Joined
    Jul 2007
    Posts
    78
    Location
    I don't know what I am doing wrong, I could not get the result I want. While executing the code there is a circular reference error. Secondly only the cell below the active cell is copied but the content is not as the active cell. The data is the copied cell is "=IF($D2="","",D$1)". ???

  6. #6
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    Which is the activecell when you run it?
    ____________________________________________
    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

  7. #7
    VBAX Regular
    Joined
    Jul 2007
    Posts
    78
    Location
    My mistake. I have it the other way around. It is now working. thx

  8. #8
    VBAX Regular
    Joined
    Jul 2007
    Posts
    78
    Location
    I spoke too fast. Although now the code is copying down the active cell but instead of copying the content of the active cell this is copied, "=IF($D2="","",D$1)"

  9. #9
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    But isn't the result the value of the activecell?
    ____________________________________________
    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

  10. #10
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    I also ask again, what is the activecell when you run this?
    ____________________________________________
    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

  11. #11
    VBAX Regular
    Joined
    Jul 2007
    Posts
    78
    Location
    No, the active cell have a different value. The formula is Cell A1 (the active cell) is E1+F1

  12. #12
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    E1+F1 is two cells, there is only one activecell.

    It must be me, but you guys are really confusing me today.

    Here is another suggesrion

    [vba]

    Dim LastRow As Long
    Dim rng As Range
    With ActiveCell

    LastRow = Cells(Rows.Count, "D").End(xlUp).Row
    Set rng = .Resize(LastRow).SpecialCells(xlCellTypeBlanks)
    .Copy .Resize(LastRow)
    rng.ClearContents
    End With
    [/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

  13. #13
    VBAX Regular
    Joined
    Jul 2007
    Posts
    78
    Location
    Sorry, the active is A1 which has a formula of E1+F1.

  14. #14
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    Modification of my last offering then

    [vba]

    Dim LastRow As Long
    Dim rng As Range
    With ActiveCell

    LastRow = Cells(Rows.Count, "D").End(xlUp).Row
    Set rng = Cells(.Row + 1, "D").Resize(LastRow).SpecialCells(xlCellTypeBlanks).Offset(0, .Column - 4)
    .Copy .Resize(LastRow)
    rng.ClearContents
    End With
    [/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

  15. #15
    VBAX Regular
    Joined
    Jul 2007
    Posts
    78
    Location
    Thx. It now appears to be working the way I hope it would.

  16. #16
    VBAX Regular
    Joined
    Jul 2007
    Posts
    78
    Location
    Thx. It now appears to be working the way I hope it would.

  17. #17
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    Great, we finally got there :smile
    ____________________________________________
    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

  18. #18
    VBAX Regular
    Joined
    Jul 2007
    Posts
    78
    Location
    Xld,

    I wonder if you could help to improve on this macro. At the present moment this macro is very specific as to the reference "criteria" position, which is to the 4 position to the right of the active cell. What should the codes be if it to the right? Can a input box be created to ask for input of the reference cell? That will be wonderful if this can be done.

    Thx in advance for any suggestionn and help.

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

    [vba]

    Dim LastRow As Long
    Dim StartCell As Range
    Dim rng As Range

    Set StartCell = Application.InputBox("Select first cell of match range with the mouse", Type:=8)
    If Not StartCell Is Nothing Then

    With ActiveCell

    LastRow = Cells(Rows.Count, StartCell.Column).End(xlUp).Row
    .Offset(1, 0).Resize(LastRow - 1).ClearContents
    Set rng = Cells(.Row + 1, StartCell.Column).Resize(LastRow).SpecialCells(xlCellTypeBlanks).Offset(0, .Column - StartCell.Column)
    .Copy .Resize(LastRow)
    rng.ClearContents
    End With
    End If
    [/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

  20. #20
    VBAX Regular
    Joined
    Jul 2007
    Posts
    78
    Location
    Xld,

    The same problem as before. When pasting down the active cell it is suppose to skip over blank reference cell and continue pasting when the reference cell is not empty. Hope I make sense.

Posting Permissions

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