Advertisement
Help Keep Boards Alive. Support us by going ad free today. See here: https://subscriptions.boards.ie/.
If we do not hit our goal we will be forced to close the site.

Current status: https://keepboardsalive.com/

Annual subs are best for most impact. If you are still undecided on going Ad Free - you can also donate using the Paypal Donate option. All contribution helps. Thank you.
https://www.boards.ie/group/1878-subscribers-forum

Private Group for paid up members of Boards.ie. Join the club.
Hi all, please see this major site announcement: https://www.boards.ie/discussion/2058427594/boards-ie-2026

Excel Macro

  • 11-08-2016 05:18PM
    #1
    Registered Users, Registered Users 2 Posts: 1,055 ✭✭✭


    I have an excel sheet with around 1000 rows and I have inserted blank rows in between. I want to copy the data from B2 into A3 and continue this down the spreadsheet. Its been a while since I used macros,ive a pretty basic knowledge too. Could someone provide some code I could use.

    Thanks


Comments

  • Registered Users, Registered Users 2 Posts: 793 ✭✭✭pillphil


    Not sure I'm reading this right, you have this?

    394152.PNG

    And you want this?
    394151.PNG

    Put
    =(B2)
    

    in A2 and drag it down?


  • Moderators, Politics Moderators, Paid Member Posts: 44,374 Mod ✭✭✭✭Seth Brundle


    It depends on whether you want to do it all in one go via Copy/Paste or do it line by line...
    Sub CopyDown()
        Range("B2").Select
        Range(Selection, Selection.End(xlDown)).Select
        Selection.Copy
        Range("A3").Select
        ActiveSheet.Paste
    End Sub
    
    Sub LineByLine()
        Dim i As Integer
        For i = 2 To ActiveSheet.Range("B65536").End(xlUp).Row    
            
            Range("A" & i + 1).Value = Range("B" & i).Value
        Next
    End Sub
    

    Help Keep Boards Alive. Support us by going ad free today. See here: https://subscriptions.boards.ie/ .



  • Moderators, Technology & Internet Moderators Posts: 1,338 Mod ✭✭✭✭croo


    @pillphil a little typo there I think?
    pillphil wrote: »
    in A2 and drag it down?
    You meant in A3 right?


  • Registered Users, Registered Users 2 Posts: 793 ✭✭✭pillphil


    Oops


  • Registered Users, Registered Users 2 Posts: 1,055 ✭✭✭Euphoriasean


    pillphil wrote: »
    Not sure I'm reading this right, you have this?

    394152.PNG

    And you want this?
    394151.PNG

    Put
    =(B2)
    

    in A2 and drag it down?

    Thanks for the reply. The problem with this is I have data in a2,a4,a6 etc that I do not want to remove. If I copy down all these cells will be blank.


  • Advertisement
  • Registered Users, Registered Users 2 Posts: 1,055 ✭✭✭Euphoriasean


    kbannon wrote: »
    It depends on whether you want to do it all in one go via Copy/Paste or do it line by line...
    Sub CopyDown()
        Range("B2").Select
        Range(Selection, Selection.End(xlDown)).Select
        Selection.Copy
        Range("A3").Select
        ActiveSheet.Paste
    End Sub
    
    Sub LineByLine()
        Dim i As Integer
        For i = 2 To ActiveSheet.Range("B65536").End(xlUp).Row    
            
            Range("A" & i + 1).Value = Range("B" & i).Value
        Next
    End Sub
    

    Thanks. The line by line code works fine but as per my post above I have data in a2,a4,a6 etc. This again will leave them blank. I need to run a macro that can copy data from say a3 to b2 then b4 to a5 then b6 to a7 etc. Apologies if I am not explaining myself very well.


  • Registered Users, Registered Users 2 Posts: 793 ✭✭✭pillphil


    There's definitely a better way to do this :)

    You have this?
    394212.PNG

    new column and formula
    394213.PNG

    Other formula
    394214.PNG

    Highlight both
    394215.PNG

    Drag as far as needed
    394216.PNG

    You'll need to keep both column or you can copy the value of the new column and paste it over itself and remove the original columns


  • Registered Users, Registered Users 2 Posts: 1,055 ✭✭✭Euphoriasean


    Snip 2.JPG

    This may give a better description of what I am trying to do.


  • Registered Users, Registered Users 2 Posts: 793 ✭✭✭pillphil


    My second attempt will do that in an albeit hilariously convoluted manner


  • Registered Users, Registered Users 2 Posts: 1,055 ✭✭✭Euphoriasean


    pillphil wrote: »
    There's definitely a better way to do this :)

    You have this?
    394212.PNG

    new column and formula
    394213.PNG

    Other formula
    394214.PNG

    Highlight both
    394215.PNG

    Drag as far as needed
    394216.PNG

    You'll need to keep both column or you can copy the value of the new column and paste it over itself and remove the original columns

    Yes I am a dumb a**. Thanks that is exactly what I am trying to do. Leave it to me to try and overcomplicate things.


  • Advertisement
Advertisement