Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Help with Macro

I am not very good at VB and need some help with a
Macro. I have spread sheet that is exported from another
program. We need to reformat the data in Column B. The
data comes into excell like this " 131212A" It needs
to look like this "13-1212A". I have tried the standard
recored macro, however it just replaces the data with the
hard coded value. I need this to be able to handle
diffrent values in column B.

Any ideas would really help, I think this easy, I'm just
not a vb guy.

Thans
Chad
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Help with Macro

Sub HypenateB()
Dim rng as Range, cell as Range
On Error Resume Next
set rng = Columns(2).SpecialCells(xlConstants,xlTextValues)
On Error goto 0
if not rng is nothing then
for each cell in rng
cell.Value = Left(cell,2) & "-" & right(cell,len(cell)-2)
Next
End if
End Sub

Test it on a copy of your data.
--
Regards,
Tom Ogilvy


"Chad Holstead" wrote in message
...
I am not very good at VB and need some help with a
Macro. I have spread sheet that is exported from another
program. We need to reformat the data in Column B. The
data comes into excell like this " 131212A" It needs
to look like this "13-1212A". I have tried the standard
recored macro, however it just replaces the data with the
hard coded value. I need this to be able to handle
diffrent values in column B.

Any ideas would really help, I think this easy, I'm just
not a vb guy.

Thans
Chad



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 576
Default Help with Macro

Chad,

This seemed to work in Excel97 [watch word wrap]

Dim i As Long
i = 1
Do Until Cells(i, 2) = ""
Cells(i, 2) = Left(Trim(Cells(i, 2)), 2) & "-" & _
Right(Trim(Cells(i, 2)), Len(Trim(Cells(i, 2))) - 2)
i = i + 1
Loop

--
sb
"Chad Holstead" wrote in message
...
I am not very good at VB and need some help with a
Macro. I have spread sheet that is exported from another
program. We need to reformat the data in Column B. The
data comes into excell like this " 131212A" It needs
to look like this "13-1212A". I have tried the standard
recored macro, however it just replaces the data with the
hard coded value. I need this to be able to handle
diffrent values in column B.

Any ideas would really help, I think this easy, I'm just
not a vb guy.

Thans
Chad



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 576
Default Help with Macro

Tom,

You solution catches the spaces at the beginning of the string
" 131212A"
and results in
" - 131212A"

(see my use of Trim)

--
sb
"Tom Ogilvy" wrote in message
...
Sub HypenateB()
Dim rng as Range, cell as Range
On Error Resume Next
set rng = Columns(2).SpecialCells(xlConstants,xlTextValues)
On Error goto 0
if not rng is nothing then
for each cell in rng
cell.Value = Left(cell,2) & "-" & right(cell,len(cell)-2)
Next
End if
End Sub

Test it on a copy of your data.
--
Regards,
Tom Ogilvy


"Chad Holstead" wrote in message
...
I am not very good at VB and need some help with a
Macro. I have spread sheet that is exported from another
program. We need to reformat the data in Column B. The
data comes into excell like this " 131212A" It needs
to look like this "13-1212A". I have tried the standard
recored macro, however it just replaces the data with the
hard coded value. I need this to be able to handle
diffrent values in column B.

Any ideas would really help, I think this easy, I'm just
not a vb guy.

Thans
Chad





  #5   Report Post  
Posted to microsoft.public.excel.programming
No Name
 
Posts: n/a
Default Help with Macro

Steve,
Thanks this works great and saved me a huge headache.

Thanks
Chad
-----Original Message-----
Chad,

This seemed to work in Excel97 [watch word wrap]

Dim i As Long
i = 1
Do Until Cells(i, 2) = ""
Cells(i, 2) = Left(Trim(Cells(i, 2)), 2) & "-" & _
Right(Trim(Cells(i, 2)), Len(Trim(Cells(i, 2))) -

2)
i = i + 1
Loop

--
sb
"Chad Holstead" wrote in message
...
I am not very good at VB and need some help with a
Macro. I have spread sheet that is exported from

another
program. We need to reformat the data in Column B.

The
data comes into excell like this " 131212A" It

needs
to look like this "13-1212A". I have tried the

standard
recored macro, however it just replaces the data with

the
hard coded value. I need this to be able to handle
diffrent values in column B.

Any ideas would really help, I think this easy, I'm

just
not a vb guy.

Thans
Chad



.



  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 576
Default Help with Macro

Chad,

Glad to be of assisstance!

Keep on Exceling!

Note that a faster way would be to have Excel write the formula into a
dummy column, copy the results and paste.special xlvalues, than clear
the dummy column.

The only trick is to determine the number of rows.
But it would look something like:
Range("Z1:Z500").FormulaR1C1="=Left(Trim(RC2, 2) & "-" & _
Right(Trim(RC2), Len(Trim(RC2)) - 2)

--
sb
wrote in message
...
Steve,
Thanks this works great and saved me a huge headache.

Thanks
Chad
-----Original Message-----
Chad,

This seemed to work in Excel97 [watch word wrap]

Dim i As Long
i = 1
Do Until Cells(i, 2) = ""
Cells(i, 2) = Left(Trim(Cells(i, 2)), 2) & "-" & _
Right(Trim(Cells(i, 2)), Len(Trim(Cells(i, 2))) -

2)
i = i + 1
Loop

--
sb
"Chad Holstead" wrote in message
...
I am not very good at VB and need some help with a
Macro. I have spread sheet that is exported from

another
program. We need to reformat the data in Column B.

The
data comes into excell like this " 131212A" It

needs
to look like this "13-1212A". I have tried the

standard
recored macro, however it just replaces the data with

the
hard coded value. I need this to be able to handle
diffrent values in column B.

Any ideas would really help, I think this easy, I'm

just
not a vb guy.

Thans
Chad



.



  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Help with Macro

Thanks for point that out

Sub HypenateB()
Dim rng as Range, cell as Range
On Error Resume Next
set rng = Columns(2).SpecialCells(xlConstants,xlTextValues)
On Error goto 0
if not rng is nothing then
for each cell in rng
cell.Value = Left(trim(cell),2) & "-" & _
right(Trim(cell),len(trim(cell))-2)
Next
End if
End Sub

or

Sub HypenateB()
Dim rng as Range, cell as Range
On Error Resume Next
set rng = Columns(2).SpecialCells(xlConstants,xlTextValues)
On Error goto 0
if not rng is nothing then
for each cell in rng
sCell = Trim(cell)
cell.Value = Left(scell,2) & "-" & _
right(scell,len(scell)-2)
Next
End if
End Sub

--
Regards,
Tom Ogilvy


steve wrote in message
...
Tom,

You solution catches the spaces at the beginning of the string
" 131212A"
and results in
" - 131212A"

(see my use of Trim)

--
sb
"Tom Ogilvy" wrote in message
...
Sub HypenateB()
Dim rng as Range, cell as Range
On Error Resume Next
set rng = Columns(2).SpecialCells(xlConstants,xlTextValues)
On Error goto 0
if not rng is nothing then
for each cell in rng
cell.Value = Left(cell,2) & "-" & right(cell,len(cell)-2)
Next
End if
End Sub

Test it on a copy of your data.
--
Regards,
Tom Ogilvy


"Chad Holstead" wrote in message
...
I am not very good at VB and need some help with a
Macro. I have spread sheet that is exported from another
program. We need to reformat the data in Column B. The
data comes into excell like this " 131212A" It needs
to look like this "13-1212A". I have tried the standard
recored macro, however it just replaces the data with the
hard coded value. I need this to be able to handle
diffrent values in column B.

Any ideas would really help, I think this easy, I'm just
not a vb guy.

Thans
Chad







  #8   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Help with Macro

Steve -

Think you meant to use quotes about the various portions including putting
the & within the formula and with quotes around the hypen. Something like
this:


Range("Z1:Z500").Formula = "=LEFT(TRIM(B1),2)" & _
"&""-""&" & "RIGHT(TRIM(B1),LEN(TRIM(B1))-2)"


Testing in the immediate window to be sure

? "=LEFT(TRIM(B1),2)" & _
"&""-""&" & "RIGHT(TRIM(B1),LEN(TRIM(B1))-2)"
=LEFT(TRIM(B1),2)&"-"&RIGHT(TRIM(B1),LEN(TRIM(B1))-2)

Since most people use A1 notation, I have included that as a variation.

--
Regards,
Tom Ogilvy

steve wrote in message
...
Chad,

Glad to be of assisstance!

Keep on Exceling!

Note that a faster way would be to have Excel write the formula into a
dummy column, copy the results and paste.special xlvalues, than clear
the dummy column.

The only trick is to determine the number of rows.
But it would look something like:
Range("Z1:Z500").FormulaR1C1="=Left(Trim(RC2, 2) & "-" & _
Right(Trim(RC2), Len(Trim(RC2)) - 2)

--
sb
wrote in message
...
Steve,
Thanks this works great and saved me a huge headache.

Thanks
Chad
-----Original Message-----
Chad,

This seemed to work in Excel97 [watch word wrap]

Dim i As Long
i = 1
Do Until Cells(i, 2) = ""
Cells(i, 2) = Left(Trim(Cells(i, 2)), 2) & "-" & _
Right(Trim(Cells(i, 2)), Len(Trim(Cells(i, 2))) -

2)
i = i + 1
Loop

--
sb
"Chad Holstead" wrote in message
...
I am not very good at VB and need some help with a
Macro. I have spread sheet that is exported from

another
program. We need to reformat the data in Column B.

The
data comes into excell like this " 131212A" It

needs
to look like this "13-1212A". I have tried the

standard
recored macro, however it just replaces the data with

the
hard coded value. I need this to be able to handle
diffrent values in column B.

Any ideas would really help, I think this easy, I'm

just
not a vb guy.

Thans
Chad


.





  #9   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 576
Default Help with Macro

Tom,

Thanks!

But as always - your solutions are always so much more elegant! And
simpler...

--
sb
"Tom Ogilvy" wrote in message
...
Steve -

Think you meant to use quotes about the various portions including putting
the & within the formula and with quotes around the hypen. Something like
this:


Range("Z1:Z500").Formula = "=LEFT(TRIM(B1),2)" & _
"&""-""&" & "RIGHT(TRIM(B1),LEN(TRIM(B1))-2)"


Testing in the immediate window to be sure

? "=LEFT(TRIM(B1),2)" & _
"&""-""&" & "RIGHT(TRIM(B1),LEN(TRIM(B1))-2)"
=LEFT(TRIM(B1),2)&"-"&RIGHT(TRIM(B1),LEN(TRIM(B1))-2)

Since most people use A1 notation, I have included that as a variation.

--
Regards,
Tom Ogilvy

steve wrote in message
...
Chad,

Glad to be of assisstance!

Keep on Exceling!

Note that a faster way would be to have Excel write the formula into a
dummy column, copy the results and paste.special xlvalues, than clear
the dummy column.

The only trick is to determine the number of rows.
But it would look something like:
Range("Z1:Z500").FormulaR1C1="=Left(Trim(RC2, 2) & "-" & _
Right(Trim(RC2), Len(Trim(RC2)) - 2)

--
sb
wrote in message
...
Steve,
Thanks this works great and saved me a huge headache.

Thanks
Chad
-----Original Message-----
Chad,

This seemed to work in Excel97 [watch word wrap]

Dim i As Long
i = 1
Do Until Cells(i, 2) = ""
Cells(i, 2) = Left(Trim(Cells(i, 2)), 2) & "-" & _
Right(Trim(Cells(i, 2)), Len(Trim(Cells(i, 2))) -
2)
i = i + 1
Loop

--
sb
"Chad Holstead" wrote in message
...
I am not very good at VB and need some help with a
Macro. I have spread sheet that is exported from
another
program. We need to reformat the data in Column B.
The
data comes into excell like this " 131212A" It
needs
to look like this "13-1212A". I have tried the
standard
recored macro, however it just replaces the data with
the
hard coded value. I need this to be able to handle
diffrent values in column B.

Any ideas would really help, I think this easy, I'm
just
not a vb guy.

Thans
Chad


.







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
Macro recorded... tabs & file names changed, macro hangs Steve Excel Worksheet Functions 3 October 30th 09 11:41 AM
Macro Help Needed - Excel 2007 - Print Macro with Auto Sort Gavin Excel Worksheet Functions 0 May 17th 07 01:20 PM
My excel macro recorder no longer shows up when recording macro jack Excel Discussion (Misc queries) 1 February 5th 07 09:31 PM
My excel macro recorder no longer shows up when recording macro jack Excel Discussion (Misc queries) 3 February 5th 07 08:22 PM
using a cell value to control a counter inside a macro and displaying macro value ocset Excel Worksheet Functions 1 September 10th 06 05:32 AM


All times are GMT +1. The time now is 03:33 AM.

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

About Us

"It's about Microsoft Excel"