Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Edit information in a cell and not change content

I have long lists of information that have been downloaded from a serve
and it needs to be formatted in a specific way. The information i
each cell is consistant in size but requires spaces at specific spots.
examples:

040001000000000 before change
04 0001 00 000 00 00 after change


040005SW0010000 before change
04 0005 SW 001 00 00 after change

I know this can be done, but I don't seem to be able to find the righ
way to write the macro to make this work.

The Cell Format dosen't change the information either.

Any help is appreciated.

Thank

--
Message posted from http://www.ExcelForum.com

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Edit information in a cell and not change content

Dim sStr as String, sStr1 as String
sStr = Cell.Text
sStr1 = Left(sStr,2) & " " & Mid(sStr,3,4) & " " & _
Mid(sStr,7,2) & " " & Mid(sStr,9,3) & " " & Mid(sStr,12,2) _
& " " & Right(sStr,2)
Cell.Value = sStr1


Verify in the immediate window:

sStr = "040005SW0010000"
sStr1 = Left(sStr,2) & " " & Mid(sStr,3,4) & " " & _
Mid(sStr,7,2) & " " & Mid(sStr,9,3) & " " & Mid(sStr,12,2) _
& " " & Right(sStr,2)
? sStr1
04 0005 SW 001 00 00

--
Regards,
Tom Ogilvy

shively5 wrote in message
...
I have long lists of information that have been downloaded from a server
and it needs to be formatted in a specific way. The information in
each cell is consistant in size but requires spaces at specific spots.
examples:

040001000000000 before change
04 0001 00 000 00 00 after change


040005SW0010000 before change
04 0005 SW 001 00 00 after change

I know this can be done, but I don't seem to be able to find the right
way to write the macro to make this work.

The Cell Format dosen't change the information either.

Any help is appreciated.

Thanks


---
Message posted from http://www.ExcelForum.com/



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Edit information in a cell and not change content

Shively5,
The macro below works for me. copy it to a module.
If you are using "0" as the first charcter as your first example you
you should set you Columns to "TEXT".

HTH

Chales

Sub add_space()
Application.ScreenUpdating = False
Dim fchr, fchr1, fchr2, fchr3, fchr4, fchr5, dchr
Dim cellrange As Range
Dim lenofcell
Dim F As Long
Dim i As Long
lenofcell = Len(ActiveCell) 'SETTING LENGTH OF CELL
Set cellrange = Worksheets("sheet1").UsedRange
F = 1
For i = 1 To cellrange.Rows.Count ''''loops thru column A
fchr = Mid(cellrange(i, 1).Value, F, 2)
fchr1 = Mid(cellrange(i, 1).Value, F + 2, 4)
fchr2 = Mid(cellrange(i, 1).Value, F + 6, 2)
fchr3 = Mid(cellrange(i, 1).Value, F + 8, 3)
fchr4 = Mid(cellrange(i, 1).Value, F + 11, 2)
fchr5 = Mid(cellrange(i, 1).Value, F + 12, 2)
dchr = fchr & " " & fchr1 & " " & fchr2 _
& " " & fchr3 & " " & fchr4 & " " & fchr5
cellrange(i, 1).Offset(0, 1).Value = dchr '''' adds results t
column B
Next
End Su

--
Message posted from http://www.ExcelForum.com

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Edit information in a cell and not change content

It isn't obvious with the test data provided, but if you use

1234567890abcde

you produce
12 3456 78 90a bc cd

So you have an error in your code.

You should change to

fchr5 = Mid(cellRange(i, 1).Value, F + 13, 2)

--
Regards,
Tom Ogilvy

Charles wrote in message
...
Shively5,
The macro below works for me. copy it to a module.
If you are using "0" as the first charcter as your first example you
you should set you Columns to "TEXT".

HTH

Chales

Sub add_space()
Application.ScreenUpdating = False
Dim fchr, fchr1, fchr2, fchr3, fchr4, fchr5, dchr
Dim cellrange As Range
Dim lenofcell
Dim F As Long
Dim i As Long
lenofcell = Len(ActiveCell) 'SETTING LENGTH OF CELL
Set cellrange = Worksheets("sheet1").UsedRange
F = 1
For i = 1 To cellrange.Rows.Count ''''loops thru column A
fchr = Mid(cellrange(i, 1).Value, F, 2)
fchr1 = Mid(cellrange(i, 1).Value, F + 2, 4)
fchr2 = Mid(cellrange(i, 1).Value, F + 6, 2)
fchr3 = Mid(cellrange(i, 1).Value, F + 8, 3)
fchr4 = Mid(cellrange(i, 1).Value, F + 11, 2)
fchr5 = Mid(cellrange(i, 1).Value, F + 12, 2)
dchr = fchr & " " & fchr1 & " " & fchr2 _
& " " & fchr3 & " " & fchr4 & " " & fchr5
cellrange(i, 1).Offset(0, 1).Value = dchr '''' adds results to
column B
Next
End Sub


---
Message posted from http://www.ExcelForum.com/



  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Edit information in a cell and not change content

Tom,

Thanks for the correction, I too am still learning.

Charle

--
Message posted from http://www.ExcelForum.com



Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Change Cell Content George Excel Discussion (Misc queries) 2 March 16th 09 02:40 PM
change content of a given cell as different cells are indicated sarah Excel Worksheet Functions 1 May 21st 08 02:41 PM
Can excel take content from another cell and add information either side?? garysumpter New Users to Excel 4 November 1st 05 06:50 PM
Can excel take content from another cell and add information either side?? garysumpter Excel Worksheet Functions 1 November 1st 05 05:56 PM
Using RichTextBox to edit Cell content dlavoie Excel Discussion (Misc queries) 0 October 13th 05 06:13 PM


All times are GMT +1. The time now is 10:18 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"