Results 1 to 19 of 19

Thread: Cut And Paste Then Move TO The Cell Below.

  1. #1

    Thread Starter
    New Member
    Join Date
    Oct 2009
    Posts
    8

    Exclamation Cut And Paste Then Move TO The Cell Below.

    Hi,

    I have a huge data file which goes across in different coloumns ie. Name - Address - Shares - Number - (Repeats across the screen)

    I want to create a macro which can convert 4 coloumns at a time so it would look like:

    Name -Address - Shares - Number
    Name -Address - Shares - Number
    (Onwards).

    Please Help!

    Thanks

    Matt

  2. #2
    Discovering Life Siddharth Rout's Avatar
    Join Date
    Feb 2005
    Location
    Mumbai, India
    Posts
    12,001

    Re: Cut And Paste Then Move TO The Cell Below.

    Welcome to the forums

    Please confirm the Office version that you are using and the type of Data file that you are using...
    A good exercise for the Heart is to bend down and help another up...
    Please Mark your Thread "Resolved", if the query is solved


    MyGear:
    ★ CPU ★ Ryzen 5 5800X
    ★ GPU ★ NVIDIA GeForce RTX 3080 TI Founder Edition
    ★ RAM ★ G. Skill Trident Z RGB 32GB 3600MHz
    ★ MB ★ ASUS TUF GAMING X570 (WI-FI) ATX Gaming
    ★ Storage ★ SSD SB-ROCKET-1TB + SEAGATE 2TB Barracuda IHD
    ★ Cooling ★ NOCTUA NH-D15 CHROMAX BLACK 140mm + 10 of Noctua NF-F12 PWM
    ★ PSU ★ ANTEC HCG-1000-EXTREME 1000 Watt 80 Plus Gold Fully Modular PSU
    ★ Case ★ LIAN LI PC-O11 DYNAMIC XL ROG (BLACK) (G99.O11DXL-X)
    ★ Monitor ★ LG Ultragear 27" 240Hz Gaming Monitor
    ★ Keyboard ★ TVS Electronics Gold Keyboard
    ★ Mouse ★ Logitech G502 Hero

  3. #3

    Thread Starter
    New Member
    Join Date
    Oct 2009
    Posts
    8

    Re: Cut And Paste Then Move TO The Cell Below.

    Thanks

    I'm Using Excel 2007 and the data file is a .csv,

    cheers

    Matt

  4. #4
    Discovering Life Siddharth Rout's Avatar
    Join Date
    Feb 2005
    Location
    Mumbai, India
    Posts
    12,001

    Re: Cut And Paste Then Move TO The Cell Below.

    Ok That shouldn't be a problem.

    Search the forums on how to loop through excel cells. Also do you also know how to record a macro in 2007?
    A good exercise for the Heart is to bend down and help another up...
    Please Mark your Thread "Resolved", if the query is solved


    MyGear:
    ★ CPU ★ Ryzen 5 5800X
    ★ GPU ★ NVIDIA GeForce RTX 3080 TI Founder Edition
    ★ RAM ★ G. Skill Trident Z RGB 32GB 3600MHz
    ★ MB ★ ASUS TUF GAMING X570 (WI-FI) ATX Gaming
    ★ Storage ★ SSD SB-ROCKET-1TB + SEAGATE 2TB Barracuda IHD
    ★ Cooling ★ NOCTUA NH-D15 CHROMAX BLACK 140mm + 10 of Noctua NF-F12 PWM
    ★ PSU ★ ANTEC HCG-1000-EXTREME 1000 Watt 80 Plus Gold Fully Modular PSU
    ★ Case ★ LIAN LI PC-O11 DYNAMIC XL ROG (BLACK) (G99.O11DXL-X)
    ★ Monitor ★ LG Ultragear 27" 240Hz Gaming Monitor
    ★ Keyboard ★ TVS Electronics Gold Keyboard
    ★ Mouse ★ Logitech G502 Hero

  5. #5

    Thread Starter
    New Member
    Join Date
    Oct 2009
    Posts
    8

    Re: Cut And Paste Then Move TO The Cell Below.

    Yea i do no how to record a macro but i'm not good at all and writing VB code.

    Cheers

  6. #6
    Discovering Life Siddharth Rout's Avatar
    Join Date
    Feb 2005
    Location
    Mumbai, India
    Posts
    12,001

    Re: Cut And Paste Then Move TO The Cell Below.

    Yea i do no how to record a macro but i'm not good at all and writing VB code.
    Thats ok

    Now did you search the forums on how to loop through excel cells.
    A good exercise for the Heart is to bend down and help another up...
    Please Mark your Thread "Resolved", if the query is solved


    MyGear:
    ★ CPU ★ Ryzen 5 5800X
    ★ GPU ★ NVIDIA GeForce RTX 3080 TI Founder Edition
    ★ RAM ★ G. Skill Trident Z RGB 32GB 3600MHz
    ★ MB ★ ASUS TUF GAMING X570 (WI-FI) ATX Gaming
    ★ Storage ★ SSD SB-ROCKET-1TB + SEAGATE 2TB Barracuda IHD
    ★ Cooling ★ NOCTUA NH-D15 CHROMAX BLACK 140mm + 10 of Noctua NF-F12 PWM
    ★ PSU ★ ANTEC HCG-1000-EXTREME 1000 Watt 80 Plus Gold Fully Modular PSU
    ★ Case ★ LIAN LI PC-O11 DYNAMIC XL ROG (BLACK) (G99.O11DXL-X)
    ★ Monitor ★ LG Ultragear 27" 240Hz Gaming Monitor
    ★ Keyboard ★ TVS Electronics Gold Keyboard
    ★ Mouse ★ Logitech G502 Hero

  7. #7

    Thread Starter
    New Member
    Join Date
    Oct 2009
    Posts
    8

    Re: Cut And Paste Then Move TO The Cell Below.

    Yes, Nothing came up. ??

  8. #8
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: Cut And Paste Then Move TO The Cell Below.

    Convert columns as in Merging the columns so the four become a single column?
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  9. #9

    Thread Starter
    New Member
    Join Date
    Oct 2009
    Posts
    8

    Re: Cut And Paste Then Move TO The Cell Below.

    No as One Go below another.

  10. #10
    Discovering Life Siddharth Rout's Avatar
    Join Date
    Feb 2005
    Location
    Mumbai, India
    Posts
    12,001

    Re: Cut And Paste Then Move TO The Cell Below.

    @Rob; no Rob, it won't work that way. I suspect the data is in one row and the OP wants to arrange it in sets of 4 one below the other....

    They are plenty of threads which will tell you how to loop thru excel cells. Can you upload a sample of your workbook?
    A good exercise for the Heart is to bend down and help another up...
    Please Mark your Thread "Resolved", if the query is solved


    MyGear:
    ★ CPU ★ Ryzen 5 5800X
    ★ GPU ★ NVIDIA GeForce RTX 3080 TI Founder Edition
    ★ RAM ★ G. Skill Trident Z RGB 32GB 3600MHz
    ★ MB ★ ASUS TUF GAMING X570 (WI-FI) ATX Gaming
    ★ Storage ★ SSD SB-ROCKET-1TB + SEAGATE 2TB Barracuda IHD
    ★ Cooling ★ NOCTUA NH-D15 CHROMAX BLACK 140mm + 10 of Noctua NF-F12 PWM
    ★ PSU ★ ANTEC HCG-1000-EXTREME 1000 Watt 80 Plus Gold Fully Modular PSU
    ★ Case ★ LIAN LI PC-O11 DYNAMIC XL ROG (BLACK) (G99.O11DXL-X)
    ★ Monitor ★ LG Ultragear 27" 240Hz Gaming Monitor
    ★ Keyboard ★ TVS Electronics Gold Keyboard
    ★ Mouse ★ Logitech G502 Hero

  11. #11

    Thread Starter
    New Member
    Join Date
    Oct 2009
    Posts
    8

    Re: Cut And Paste Then Move TO The Cell Below.

    Yea i can upload, where do i upload it 2?

  12. #12
    Discovering Life Siddharth Rout's Avatar
    Join Date
    Feb 2005
    Location
    Mumbai, India
    Posts
    12,001

    Re: Cut And Paste Then Move TO The Cell Below.

    Quote Originally Posted by Gevaux19 View Post
    Yea i can upload, where do i upload it 2?
    http://www.vbforums.com/faq.php?faq=...b3_attachments
    A good exercise for the Heart is to bend down and help another up...
    Please Mark your Thread "Resolved", if the query is solved


    MyGear:
    ★ CPU ★ Ryzen 5 5800X
    ★ GPU ★ NVIDIA GeForce RTX 3080 TI Founder Edition
    ★ RAM ★ G. Skill Trident Z RGB 32GB 3600MHz
    ★ MB ★ ASUS TUF GAMING X570 (WI-FI) ATX Gaming
    ★ Storage ★ SSD SB-ROCKET-1TB + SEAGATE 2TB Barracuda IHD
    ★ Cooling ★ NOCTUA NH-D15 CHROMAX BLACK 140mm + 10 of Noctua NF-F12 PWM
    ★ PSU ★ ANTEC HCG-1000-EXTREME 1000 Watt 80 Plus Gold Fully Modular PSU
    ★ Case ★ LIAN LI PC-O11 DYNAMIC XL ROG (BLACK) (G99.O11DXL-X)
    ★ Monitor ★ LG Ultragear 27" 240Hz Gaming Monitor
    ★ Keyboard ★ TVS Electronics Gold Keyboard
    ★ Mouse ★ Logitech G502 Hero

  13. #13

    Thread Starter
    New Member
    Join Date
    Oct 2009
    Posts
    8

    Re: Cut And Paste Then Move TO The Cell Below.

    Attahced is the sample of my workbook.
    Attached Files Attached Files

  14. #14
    Discovering Life Siddharth Rout's Avatar
    Join Date
    Feb 2005
    Location
    Mumbai, India
    Posts
    12,001

    Re: Cut And Paste Then Move TO The Cell Below.

    You have to zip your excel file and then upload it...
    A good exercise for the Heart is to bend down and help another up...
    Please Mark your Thread "Resolved", if the query is solved


    MyGear:
    ★ CPU ★ Ryzen 5 5800X
    ★ GPU ★ NVIDIA GeForce RTX 3080 TI Founder Edition
    ★ RAM ★ G. Skill Trident Z RGB 32GB 3600MHz
    ★ MB ★ ASUS TUF GAMING X570 (WI-FI) ATX Gaming
    ★ Storage ★ SSD SB-ROCKET-1TB + SEAGATE 2TB Barracuda IHD
    ★ Cooling ★ NOCTUA NH-D15 CHROMAX BLACK 140mm + 10 of Noctua NF-F12 PWM
    ★ PSU ★ ANTEC HCG-1000-EXTREME 1000 Watt 80 Plus Gold Fully Modular PSU
    ★ Case ★ LIAN LI PC-O11 DYNAMIC XL ROG (BLACK) (G99.O11DXL-X)
    ★ Monitor ★ LG Ultragear 27" 240Hz Gaming Monitor
    ★ Keyboard ★ TVS Electronics Gold Keyboard
    ★ Mouse ★ Logitech G502 Hero

  15. #15
    Don't Panic! Ecniv's Avatar
    Join Date
    Nov 2000
    Location
    Amsterdam...
    Posts
    5,343

    Re: Cut And Paste Then Move TO The Cell Below.

    Best way might be to open a connection to the file, read in characters and look for the tab character (9). (column) Count these and when count > 4 (or 5?) then move down a line and reset the column back to 1.

    You can do this in vba coding :
    - open
    - close #
    - left / right / mid <--- might be useful
    - input <--- think this is the bit for getting a character

    The help files in excel should cover these functions.


    Alternatively you can use an API call to use the file as a stream and do the same, may be slightly quicker, but is harder to code.

    Just options....

    Is there any line/record delimiter?

    BOFH Now, BOFH Past, Information on duplicates

    Feeling like a fly on the inside of a closed window (Thunk!)
    If I post a lot, it is because I am bored at work! ;D Or stuck...
    * Anything I post can be only my opinion. Advice etc is up to you to persue...

  16. #16

    Thread Starter
    New Member
    Join Date
    Oct 2009
    Posts
    8

    Re: Cut And Paste Then Move TO The Cell Below.

    Ecniv,

    I havent got a clue about Vb coding. lol.

    Koolsid,

    Just open it in excel with tab delimiter.

    Regards

  17. #17
    Discovering Life Siddharth Rout's Avatar
    Join Date
    Feb 2005
    Location
    Mumbai, India
    Posts
    12,001

    Re: Cut And Paste Then Move TO The Cell Below.

    Just a sample

    Amend it as per your requirements...

    vb Code:
    1. Sub Sample()
    2.     Dim i As Long
    3.    
    4.     '~~> Say data is in 1st Row starting from A1
    5.     i = 1
    6.        
    7.     For i = 1 To 4
    8.         '~~> So next range will start from E column
    9.         Range("E" & i).Select
    10.         '~~> Select till end
    11.         Range(Selection, Selection.End(xlToRight)).Select
    12.         '~~> Cut selection
    13.         Selection.Cut
    14.         '~~> Paste it one row below in column A
    15.         Range("A" & i + 1).Select
    16.         ActiveSheet.Paste
    17.     Next
    18. End Sub
    A good exercise for the Heart is to bend down and help another up...
    Please Mark your Thread "Resolved", if the query is solved


    MyGear:
    ★ CPU ★ Ryzen 5 5800X
    ★ GPU ★ NVIDIA GeForce RTX 3080 TI Founder Edition
    ★ RAM ★ G. Skill Trident Z RGB 32GB 3600MHz
    ★ MB ★ ASUS TUF GAMING X570 (WI-FI) ATX Gaming
    ★ Storage ★ SSD SB-ROCKET-1TB + SEAGATE 2TB Barracuda IHD
    ★ Cooling ★ NOCTUA NH-D15 CHROMAX BLACK 140mm + 10 of Noctua NF-F12 PWM
    ★ PSU ★ ANTEC HCG-1000-EXTREME 1000 Watt 80 Plus Gold Fully Modular PSU
    ★ Case ★ LIAN LI PC-O11 DYNAMIC XL ROG (BLACK) (G99.O11DXL-X)
    ★ Monitor ★ LG Ultragear 27" 240Hz Gaming Monitor
    ★ Keyboard ★ TVS Electronics Gold Keyboard
    ★ Mouse ★ Logitech G502 Hero

  18. #18
    Don't Panic! Ecniv's Avatar
    Join Date
    Nov 2000
    Location
    Amsterdam...
    Posts
    5,343

    Re: Cut And Paste Then Move TO The Cell Below.

    Problem is that you are opening a huge datafile, and excel doesn't have a huge amount of columns... 4 per record, approx 255 columns, means not many records, or that the space below may contain data...

    Hence the open and read a file.

    If I get some time I'll write a simple import loop and comment it.. you can then tweak as applicable...

    BOFH Now, BOFH Past, Information on duplicates

    Feeling like a fly on the inside of a closed window (Thunk!)
    If I post a lot, it is because I am bored at work! ;D Or stuck...
    * Anything I post can be only my opinion. Advice etc is up to you to persue...

  19. #19
    Don't Panic! Ecniv's Avatar
    Join Date
    Nov 2000
    Location
    Amsterdam...
    Posts
    5,343

    Re: Cut And Paste Then Move TO The Cell Below.

    Code:
    Option Explicit
    
    Public Sub ImportDataFile()
        
        Dim sht As Worksheet
        Dim strChar As String
        Dim strColumnData As String
        Dim lngColumn As Long, lngRow As Long
        
        
        Set sht = ActiveSheet
        
    '---- close the channel - incase its still open
        Close #1
        
        Open "C:\DataFile.csv" For Input As #1
        
        lngColumn = 1
        lngRow = 1
        strChar = String(1, " ")
        
    '---- keep looping until the file runs out
        Do Until EOF(1)
            strChar = Input(1, #1)
            
    '---- if its the separator
            If Asc(strChar) = 9 Then
                
    '---- output the data and
    '---- move the column
                sht.Cells(lngRow, lngColumn) = strColumnData
                lngColumn = lngColumn + 1
                strColumnData = ""
                
    '---- if the column is > 4 then reset the column and add one to the row
                If lngColumn > 4 Then
                    lngColumn = 1
                    lngRow = lngRow + 1
                End If
            Else
            
    '---- add the char to the data
    '---- * you could add extra checks here to remove speechmarks etc
                strColumnData = strColumnData & strChar
            
            End If
        
        Loop
        sht.Cells(lngRow, lngColumn) = strColumnData
        '---- dump the last of the data in the cell
        
    '---- close the channel
        Close #1
        
        
        Set sht = Nothing
    End Sub
    Drop that in a module - then run it and see if it works... (In excel!)
    If it does, see if you understand how I did it.

    might not be fast on huge files tho...

    BOFH Now, BOFH Past, Information on duplicates

    Feeling like a fly on the inside of a closed window (Thunk!)
    If I post a lot, it is because I am bored at work! ;D Or stuck...
    * Anything I post can be only my opinion. Advice etc is up to you to persue...

Posting Permissions

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



Click Here to Expand Forum to Full Width