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

A need for a macro that is beyond my ability....This macro is to be used in a
csv file.

In Column "C" I have Part numbers that are formated as 00000000 or
50004590...these do not cause me any issues...and should be left alone.

But in Column "C" I can also have part numbers that are formated as 000.0000
or 440.4300. Excel insists on removing any trailing 0's when opening and
saving a CSV file...whenever it sees a decimal point in Part Number.

I'd like a macro that scans column "C" and when it finds a Part number that
equals a 000.0000 format it will convert it to text and add any missing
trailing 0's (up to four).

My plan is to save as CSV but not re-open in Excel or save, which (of
course) would again strip training 0's.

Thanks in advance....Steve


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,441
Default Find & Replace Macro

Steve,

Simply rename your CSV file as a TXT file, and in the dialog that opens when
you try to open the TXT file, set your column C to be text and Excel will
ignore the .0000 issue.

HTH,
Bernie
MS Excel MVP


"Steve K" wrote in message
...
A need for a macro that is beyond my ability....This macro is to be used in
a
csv file.

In Column "C" I have Part numbers that are formated as 00000000 or
50004590...these do not cause me any issues...and should be left alone.

But in Column "C" I can also have part numbers that are formated as
000.0000
or 440.4300. Excel insists on removing any trailing 0's when opening and
saving a CSV file...whenever it sees a decimal point in Part Number.

I'd like a macro that scans column "C" and when it finds a Part number
that
equals a 000.0000 format it will convert it to text and add any missing
trailing 0's (up to four).

My plan is to save as CSV but not re-open in Excel or save, which (of
course) would again strip training 0's.

Thanks in advance....Steve



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 25
Default Find & Replace Macro

Put this macro in a separate spreadsheet (not in the csv file). Run the
macro and then save the csv file. The formatting you want should be saved in
the csv file.

Sub ValuesForCSV()
lastrow = Cells(Rows.Count, "C").End(xlUp).Row
For x = lastrow To 1 Step -1 'change To 2 if there is a header row
If Cells(x, 3).Value 10000000 Then
Cells(x, 3).NumberFormat = "General"
Else
Cells(x, 3).NumberFormat = "#.0000"
End If
Next
End Sub

--
HTH,
Data Hog


"Steve K" wrote:

A need for a macro that is beyond my ability....This macro is to be used in a
csv file.

In Column "C" I have Part numbers that are formated as 00000000 or
50004590...these do not cause me any issues...and should be left alone.

But in Column "C" I can also have part numbers that are formated as 000.0000
or 440.4300. Excel insists on removing any trailing 0's when opening and
saving a CSV file...whenever it sees a decimal point in Part Number.

I'd like a macro that scans column "C" and when it finds a Part number that
equals a 000.0000 format it will convert it to text and add any missing
trailing 0's (up to four).

My plan is to save as CSV but not re-open in Excel or save, which (of
course) would again strip training 0's.

Thanks in advance....Steve


  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 8
Default Find & Replace Macro

J - Thanks for marco help...it works perfectly. Earlier post by Bernie also
was a solution, but yours allows for less "messing" around by our group. It
simplify's the process significantly. Thanks Much !

Steve

"J_Knowles" wrote:

Put this macro in a separate spreadsheet (not in the csv file). Run the
macro and then save the csv file. The formatting you want should be saved in
the csv file.

Sub ValuesForCSV()
lastrow = Cells(Rows.Count, "C").End(xlUp).Row
For x = lastrow To 1 Step -1 'change To 2 if there is a header row
If Cells(x, 3).Value 10000000 Then
Cells(x, 3).NumberFormat = "General"
Else
Cells(x, 3).NumberFormat = "#.0000"
End If
Next
End Sub

--
HTH,
Data Hog


"Steve K" wrote:

A need for a macro that is beyond my ability....This macro is to be used in a
csv file.

In Column "C" I have Part numbers that are formated as 00000000 or
50004590...these do not cause me any issues...and should be left alone.

But in Column "C" I can also have part numbers that are formated as 000.0000
or 440.4300. Excel insists on removing any trailing 0's when opening and
saving a CSV file...whenever it sees a decimal point in Part Number.

I'd like a macro that scans column "C" and when it finds a Part number that
equals a 000.0000 format it will convert it to text and add any missing
trailing 0's (up to four).

My plan is to save as CSV but not re-open in Excel or save, which (of
course) would again strip training 0's.

Thanks in advance....Steve


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
Find and replace macro edeaston Excel Discussion (Misc queries) 3 January 12th 09 10:51 AM
Find & Replace and Find & Insert macro help needed RS Excel Programming 2 January 29th 07 07:35 AM
Using Find and Replace to replace " in a macro snail30152 Excel Programming 1 April 13th 06 11:58 PM
Help with find and replace macro davegb Excel Programming 5 June 23rd 05 11:31 PM
Using Find & Replace in macro Bob C[_3_] Excel Programming 11 October 30th 03 07:02 PM


All times are GMT +1. The time now is 06:35 AM.

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"