Consulting

Results 1 to 12 of 12

Thread: Solved: Duplicating the cell above the current cell

  1. #1
    VBAX Regular
    Joined
    Oct 2010
    Location
    Upstate NY
    Posts
    6
    Location

    Solved: Duplicating the cell above the current cell

    Brand new to Excel VBA, used Quattro Pro for years

    Question : trying to duplicate the cell above the active cell down through a column until reaching a '999' stop ... the following isn't working for me :

    [vba]Dim PSRegCell
    For Each PSRegCell In Range("A1")
    If ActiveCell.Value <> 999 Then
    ActiveCell.Offset(-1, 0).Range("a1").Select
    Selection.Copy
    ActiveCell.Offset(1, 0).Range("A1").Select
    ActiveSheet.Paste
    ActiveCell.Offset(1, 0).Range("A1").Select
    Else: End
    End If
    Next PSRegCell[/vba]
    I know this is simple, but I've been handed a project for which I'm unprepared ... thanks !
    Last edited by Aussiebear; 10-05-2010 at 03:09 PM. Reason: added VBA Tags to code

  2. #2
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    A bit more detail.

    Are you trying to insert a new row and copy the row above, your code will overwrite the row?

    What is the 999 test for, is it meant to be the end? Is there a 999 cell, and if so, are there cells after it.

    Maybe give a before and after example.
    ____________________________________________
    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
    Moderator VBAX Master austenr's Avatar
    Joined
    Sep 2004
    Location
    Maine
    Posts
    2,033
    Location
    So you are saying you want to copy the contents of cell A1 down until you get to a cell withthe value of 999?
    Peace of mind is found in some of the strangest places.

  4. #4
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    Quote Originally Posted by austenr
    So you are saying you want to copy the contents of cell A1 down until you get to a cell with the value of 999?
    Touché
    ____________________________________________
    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
    Oct 2010
    Location
    Upstate NY
    Posts
    6
    Location
    no, copycontents of A1 to A2, then go to A3, check for '999', if not, then copy A2 to A3, then go to A4, check for '999', then copy A3 to A4 ... ad finitum

    some cells will have contents, some will not

  6. #6
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    I don't think this is what you want, but it is what I think you are asking for

    [vba]

    Dim PSRegCell As Range

    With ActiveSheet

    For Each PSRegCell In Range(Range("A2"), Range("A1").End(xlDown))
    With PSRegCell
    If .Value <> 999 Then
    .Offset(-1, 0).Copy .Offset(0, 0)
    End If
    End With
    Next PSRegCell
    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

  7. #7
    VBAX Regular
    Joined
    Oct 2010
    Location
    Upstate NY
    Posts
    6
    Location
    no, not working

    using excel 2010

    here's a simple before (Col B) / and after (Col D)

  8. #8
    Moderator VBAX Master austenr's Avatar
    Joined
    Sep 2004
    Location
    Maine
    Posts
    2,033
    Location
    Why on earth would you want to do that? Just asking?
    Peace of mind is found in some of the strangest places.

  9. #9
    VBAX Regular
    Joined
    Oct 2010
    Location
    Upstate NY
    Posts
    6
    Location
    I get a "crosstab" of accounts from an external database, which I paste into excel, from which I will need to do vlookups on concatenated columns ... each of the column cells needs to be filled to get a valid lookup ... I can copy and paste down the blank cells in the column, but it's about 2000 rows and 90 or so different data elements with blank cells in between

    in other words, you don't want to know

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

    Dim PSRegCell As Range

    With ActiveSheet

    For Each PSRegCell In Range(.Range("B2"), .Range("B" & .Rows.Count).End(xlUp))
    With PSRegCell
    If .Value <> 999 Then
    If .Value = "" Then
    .Offset(-1, 0).Copy .Offset(0, 0)
    End If
    End If
    End With
    Next PSRegCell
    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

  11. #11
    VBAX Regular
    Joined
    Oct 2010
    Location
    Upstate NY
    Posts
    6
    Location
    perfect, nice work, saved my week !

  12. #12
    You seem to have posted this question twice. The first time was under the topic Conditional Duplicating down a column
    What happens if you get scared half to death twice?

Posting Permissions

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