Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

Excel Macro

Options
  • 11-08-2016 6:18pm
    #1
    Registered Users Posts: 1,022 ✭✭✭


    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 Posts: 778 ✭✭✭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 Posts: 39,560 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
    


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


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


  • Registered Users Posts: 778 ✭✭✭pillphil


    Oops


  • Registered Users Posts: 1,022 ✭✭✭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 Posts: 1,022 ✭✭✭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 Posts: 778 ✭✭✭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 Posts: 1,022 ✭✭✭Euphoriasean


    Snip 2.JPG

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


  • Registered Users Posts: 778 ✭✭✭pillphil


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


  • Registered Users Posts: 1,022 ✭✭✭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