Oct 6th, 2009, 07:07 AM
#1
Thread Starter
New Member
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
Oct 6th, 2009, 12:36 PM
#2
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
Oct 7th, 2009, 02:07 AM
#3
Thread Starter
New Member
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
Oct 7th, 2009, 02:11 AM
#4
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
Oct 7th, 2009, 03:31 AM
#5
Thread Starter
New Member
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
Oct 7th, 2009, 03:38 AM
#6
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
Oct 7th, 2009, 03:42 AM
#7
Thread Starter
New Member
Re: Cut And Paste Then Move TO The Cell Below.
Oct 7th, 2009, 03:43 AM
#8
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 Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API 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
Oct 7th, 2009, 03:45 AM
#9
Thread Starter
New Member
Re: Cut And Paste Then Move TO The Cell Below.
No as One Go below another.
Oct 7th, 2009, 04:11 AM
#10
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
Oct 7th, 2009, 04:17 AM
#11
Thread Starter
New Member
Re: Cut And Paste Then Move TO The Cell Below.
Yea i can upload, where do i upload it 2?
Oct 7th, 2009, 05:10 AM
#12
Re: Cut And Paste Then Move TO The Cell Below.
Originally Posted by
Gevaux19
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
Oct 7th, 2009, 05:45 AM
#13
Thread Starter
New Member
Re: Cut And Paste Then Move TO The Cell Below.
Attahced is the sample of my workbook.
Attached Files
Oct 7th, 2009, 06:22 AM
#14
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
Oct 7th, 2009, 06:27 AM
#15
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?
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...
Oct 7th, 2009, 07:38 AM
#16
Thread Starter
New Member
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
Oct 7th, 2009, 07:53 AM
#17
Re: Cut And Paste Then Move TO The Cell Below.
Just a sample
Amend it as per your requirements...
vb Code:
Sub Sample()
Dim i As Long
'~~> Say data is in 1st Row starting from A1
i = 1
For i = 1 To 4
'~~> So next range will start from E column
Range("E" & i).Select
'~~> Select till end
Range(Selection, Selection.End(xlToRight)).Select
'~~> Cut selection
Selection.Cut
'~~> Paste it one row below in column A
Range("A" & i + 1).Select
ActiveSheet.Paste
Next
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
Oct 7th, 2009, 08:23 AM
#18
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...
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...
Oct 7th, 2009, 08:37 AM
#19
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...
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
Forum Rules
Click Here to Expand Forum to Full Width