Register Advertise with usHelp Desk Today's Posts Search

Thread Tools Search this Thread
Unread 10th Dec 2017, 09:08 AM   #1
HyperActive Warrior
War Room Member
 
Join Date: 2007
Location: Australia, S'pore, M'sia .
Posts: 157
Thanks: 14
Thanked 15 Times in 14 Posts
Default
Need VBA code snippet help...
Share on: 
fb share twitter share gplus share more share

I have a datafile with 16 char in 16 lines that I need to get into excel (16 column by 16 rows).

The sample code I have doesn't do what I want (I'm sure it is not correct code):
Sub Sample()
Dim MyData As String
Dim lineData() As String, strData() As String, myFile As String
Dim i As Long, rng As Range
myFile = Application.GetOpenFilename("RawData1 (*.txt), *.txt")

Open myFile For Binary As #1
MyData = Space$(LOF(1))
Get #1, , MyData
Close #1
' Split into wholes line
lineData() = Split(MyData, vbNewLine)
Set rng = Range("A1")
' For each line
For i = 0 To UBound(lineData)
' Split the line
strData = Split(lineData(i), "|")
' Write to the sheet
rng.Offset(i, 0).Resize(1, UBound(strData) + 1) = strData

Next
End Sub

Appreciate any and all help please.
The datafile contents is like this (note . means a blank cell):
*notice #char (including the . adds up to 16 per line)
.2A.....5C.9..6G
6..G.5471A82.D..
.8...B2...E7...A
....6AE..4GF3.87
1E7.C8..G.46FBA9
.D.....4.E.3.CG.
.F.C.2A571B.683E
A.5..9...2.C7.D.
..3.A..9.8.4.EBD
..E6.G1D.....3..
C.....7..D1..A4.
DA.....63.7EC...
3...F.9....85G..
........EB..DF98
EB.A5..2...1....
F.9.B.8..75GA.2.

Many thanks,
Tim

Last edited on 10th Dec 2017 at 09:10 AM. Reason: clarify datafile contents better
astaga is offline   Reply With Quote
Unread 12th Dec 2017, 07:50 AM   #2
Warrior Member
 
Join Date: 2017
Posts: 5
Thanks: 1
Thanked 4 Times in 3 Posts
Default
RE: Need VBA code snippet help...
Share on: 
fb share twitter share gplus share more share

Hi Tim. I don't know VBA, but this looks like something I might just use a good text editor for instead of writing a script. Are you just trying to convert to csv so you can open in excel? If so, could you just find/replace all "." with ","?
codexmonkey is offline   Reply With Quote
The Following User Says Thank You to codexmonkey For This Useful Post:
Unread 12th Dec 2017, 06:17 PM   #3
some fancy title here
War Room Member
 
tryinhere's Avatar
 
Join Date: 2009
Location: The Grim Reaper Lives Here
Posts: 2,983
Thanks: 919
Thanked 1,059 Times in 710 Posts
Default
Re: Need VBA code snippet help...
Share on: 
fb share twitter share gplus share more share

do you have a before spreadsheet and an after spreadsheet? so I can see what you want.
tryinhere is offline   Reply With Quote
Unread 13th Dec 2017, 10:03 AM   #4
VIP Warrior
War Room Member
 
Mike Anthony's Avatar
 
Join Date: 2009
Location: US of A
Posts: 11,248
Thanks: 1,830
Thanked 4,585 Times in 2,942 Posts
Default
Re: Need VBA code snippet help...
Share on: 
fb share twitter share gplus share more share

Also don't know VBA as early on I went with C# in that area (and Pyhon for most text manipulation). Question like this however are much better for Stackoverflow.


Mike Anthony is offline   Reply With Quote
The Following User Says Thank You to Mike Anthony For This Useful Post:
Unread 14th Dec 2017, 03:48 AM   #5
some fancy title here
War Room Member
 
tryinhere's Avatar
 
Join Date: 2009
Location: The Grim Reaper Lives Here
Posts: 2,983
Thanks: 919
Thanked 1,059 Times in 710 Posts
Default
Re: Need VBA code snippet help...
Share on: 
fb share twitter share gplus share more share

Whipped this up real quick for you, see spread sheet attached you will just need to copy the data the orange section and select to run the macro, it is basic but without knowing exactly what you want this will do of sorts for you.

Sub Sort16()
' Keyboard Shortcut: Ctrl+Shift+X
'
Application.ScreenUpdating = False
Range("A1").Select
Do Until ActiveCell.Value = ""
Range("B17").Value = 1
Do Until Range("B17").Value = 17
ActiveCell.Offset(0, Range("c17")).Value = ActiveCell.Offset(0, 2).Value
Range("B17").Value = Range("B17").Value + 1
Loop
ActiveCell.Offset(1, 0).Select
Loop
Application.ScreenUpdating = False
End Sub

https://screencast-o-matic.com/watch/cbl2QC2d5z

*** EDIT *** In the last line of the sub I want you to change the code from

Application.ScreenUpdating = False

to

Application.ScreenUpdating = True

oversight / sorry
Attached Files
File Type: zip 16.zip (8.5 KB, 1 views)
tryinhere is offline   Reply With Quote
The Following User Says Thank You to tryinhere For This Useful Post:
Unread 16th Dec 2017, 08:11 AM   #6
HyperActive Warrior
War Room Member
 
Join Date: 2007
Location: Australia, S'pore, M'sia .
Posts: 157
Thanks: 14
Thanked 15 Times in 14 Posts
Default
Re: Need VBA code snippet help...
Share on: 
fb share twitter share gplus share more share

#codexmonkey,
don't understand your reply?
If I replace all "." (a period) with "," (a comma) that defines/separates where blanks are to go (as a cell entry), but I'll have problems in places that have a character/value in them, since there are no commas to define these being a cell entry.

#tryinhere,
Thank you for your code.
Yes, that does the job beautifully.

Regards,
Tim
astaga is offline   Reply With Quote
The Following User Says Thank You to astaga For This Useful Post:


Bookmarks

Tags
code, snippet, vba


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off




All times are GMT -6. The time now is 11:25 PM.