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
Hi there,
There is an issue with role permissions that is being worked on at the moment.
If you are having trouble with access or permissions on regional forums please post here to get access: https://www.boards.ie/discussion/2058365403/you-do-not-have-permission-for-that#latest

Excel Macro

  • 11-08-2016 5:18pm
    #1
    Registered Users, Registered Users 2 Posts: 1,029 ✭✭✭


    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: 792 ✭✭✭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: 42,143 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,336 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: 792 ✭✭✭pillphil


    Oops


  • Registered Users, Registered Users 2 Posts: 1,029 ✭✭✭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,029 ✭✭✭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: 792 ✭✭✭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,029 ✭✭✭Euphoriasean


    Snip 2.JPG

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


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


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


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