Go Back   DeveloperBarn Forums > Databases > Microsoft Access

Sponsored Links

Discuss "excel to access need macro to find space" in the Microsoft Access forum.

Microsoft Access - Microsoft Access is a database for small to medium applications. Learn tips and tricks and best database practices here.


Reply « Previous Thread | Next Thread »  
 
LinkBack Thread Tools Display Modes
  #1  
Old August 27th, 2008, 09:16 AM
Barn Frequenter

 
Join Date: Mar 2008
Posts: 174
Thanks: 14
Thanked 0 Times in 0 Posts
Rep Power: 1
peebman2000 is an unknown quantity at this point
Question excel to access need macro to find space

Good morning everyone its peeb, i'm really not familiar with doing macros, especially in excel. I have friend that is working on an excel sheet that will be imported into access. She has like over 100 + zipcodes that she has entered into 1 cell in excel. Well she need to put a comma between the spaces of each zipcode. This is her first time working with a macro, I told I would see what I can research on it. I"m not finding much online except for

http://www.mrexcel.com/forum/showthread.php?p=1543776
Unfortantly I don't fully understand it, but I really have not sat an analized the code. I'm sure If I did with time i would.

Anyway does anyone know of like a simple macro snippet that can search a cell for spaces and insert a comma in between the spaces of zip codes.

(e.g., 44444, 44444, 44444)

I appreciate any suggestions, thanks.

Last edited by peebman2000; August 27th, 2008 at 09:18 AM. Reason: missed word
Reply With Quote
Sponsored Links
  #2  
Old August 27th, 2008, 09:42 AM
richyrich's Avatar
Moderator


 
Join Date: Mar 2008
Location: Somewhere only we know...
Posts: 395
Thanks: 26
Thanked 32 Times in 32 Posts
Blog Entries: 1
Rep Power: 1
richyrich will become famous soon enough

Awards Showcase
Classic ASP JavaScript 
Total Awards: 2

Default

Try a function like this:-
Code:
Function add_comma(cell_value As String) As String
 
add_comma = Replace(cell_value," ",", ")
 
End Function
This needs to be added as a module in VBA.

Then in a seperate cell on the spreadsheet have
Code:
=add_comma(A1)
Obviously where A1 is the cell that contains the data you want to seperate.

Hope that helps.

Comments on this post
peebman2000 agrees: Thanked Post
Reply With Quote
The Following User Says Thank You to richyrich For This Useful Post:
peebman2000 (August 27th, 2008)
  #3  
Old August 27th, 2008, 10:34 AM
Barn Frequenter

 
Join Date: Mar 2008
Posts: 174
Thanks: 14
Thanked 0 Times in 0 Posts
Rep Power: 1
peebman2000 is an unknown quantity at this point
Thumbs up rely

Hey Richy, thanks for the help. I just tried it in excel and the code works perfectly. I just forwarded my friend this link with the code for her to use and told her to call me if she needs help on it.

But thanks again dude I appreciate the reply. Have a good day.


Quote:
Originally Posted by richyrich View Post
Try a function like this:-
Code:
Function add_comma(cell_value As String) As String
 
add_comma = Replace(cell_value," ",", ")
 
End Function
This needs to be added as a module in VBA.

Then in a seperate cell on the spreadsheet have
Code:
=add_comma(A1)
Obviously where A1 is the cell that contains the data you want to seperate.

Hope that helps.
Reply With Quote
  #4  
Old August 27th, 2008, 10:44 AM
richyrich's Avatar
Moderator


 
Join Date: Mar 2008
Location: Somewhere only we know...
Posts: 395
Thanks: 26
Thanked 32 Times in 32 Posts
Blog Entries: 1
Rep Power: 1
richyrich will become famous soon enough

Awards Showcase
Classic ASP JavaScript 
Total Awards: 2

Default

Quote:
Originally Posted by peebman2000 View Post
Hey Richy, thanks for the help. I just tried it in excel and the code works perfectly. I just forwarded my friend this link with the code for her to use and told her to call me if she needs help on it.

But thanks again dude I appreciate the reply. Have a good day.
No problem...
Reply With Quote
  #5  
Old August 28th, 2008, 09:59 AM
Barn Frequenter

 
Join Date: Mar 2008
Posts: 174
Thanks: 14
Thanked 0 Times in 0 Posts
Rep Power: 1
peebman2000 is an unknown quantity at this point
Question reply

Hey Rich got another question. I worked with my friend yesterday on the excel macro and it worked thanks to your idea. But she also has zipcodes that have breaks (vbCrLf) see exampleL
55555
45666
57555

I tried playing with your VBA code below to see if I could get it to replace line breaks with commas.
Code:
Function add_comma(cell_value As String) As String
 
add_comma = Replace(cell_value,"vbCrlf ",", ")
 
End Function
And that didn't work. Is there a way to have the macro go through and look for line breaks and replace them with commas?


Quote:
Originally Posted by richyrich View Post
No problem...
Reply With Quote
  #6  
Old August 28th, 2008, 10:48 AM
richyrich's Avatar
Moderator


 
Join Date: Mar 2008
Location: Somewhere only we know...
Posts: 395
Thanks: 26
Thanked 32 Times in 32 Posts
Blog Entries: 1
Rep Power: 1
richyrich will become famous soon enough

Awards Showcase
Classic ASP JavaScript 
Total Awards: 2

Default

I presume she has used Alt+Enter to put in each line. In which case, try this:-

Code:
Function add_comma(cell_value As String) As String
 
        add_comma = Replace(cell_value, Chr(10), ", ")
 
End Function
And then call it in the same way.

Hope that helps.

Comments on this post
peebman2000 agrees: Thanked Post
Reply With Quote
The Following User Says Thank You to richyrich For This Useful Post:
peebman2000 (August 28th, 2008)
  #7  
Old August 28th, 2008, 11:29 AM
Barn Frequenter

 
Join Date: Mar 2008
Posts: 174
Thanks: 14
Thanked 0 Times in 0 Posts
Rep Power: 1
peebman2000 is an unknown quantity at this point
Thumbs up reply

Thanks again rich that worked, I just tried in excel and it worked. My friend is working on it now. Thanks again for the help.


Quote:
Originally Posted by richyrich View Post
I presume she has used Alt+Enter to put in each line. In which case, try this:-

Code:
Function add_comma(cell_value As String) As String
 
        add_comma = Replace(cell_value, Chr(10), ", ")
 
End Function
And then call it in the same way.

Hope that helps.
Reply With Quote
Reply

  DeveloperBarn Forums > Databases > Microsoft Access

Bookmarks

Thread Tools
Display Modes

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 On
Pingbacks are On
Refbacks are On
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
From excel to database/web app Rebelle Database Design Help 7 July 10th, 2008 01:36 PM
find words and change todd2006 JavaScript Programming 4 July 2nd, 2008 09:58 AM
Excel question Rebelle Microsoft Office 11 May 27th, 2008 07:22 PM
Retrieving Web Data using Excel mehere Microsoft Office 13 May 22nd, 2008 03:14 PM


All times are GMT -4. The time now is 03:24 PM.



Content Relevant URLs by vBSEO 3.2.0