Jun 11th, 2010, 08:27 AM
#1
Thread Starter
Hyperactive Member
[RESOLVED] Removing Line Feeds - Excel
My Excel addin has a feature to remove all line feeds and replace them with a space.
Originally, I had just this (and it worked fine):
Code:
Globals.ThisAddIn.Application.ScreenUpdating = False
Globals.ThisAddIn.Application.DisplayAlerts = False
Globals.ThisAddIn.Application.Selection.replace(What:=vbNewLine, Replacement:=" ")
Globals.ThisAddIn.Application.Selection.replace(What:=vbCr, Replacement:=" ")
Globals.ThisAddIn.Application.Selection.replace(What:=vbLf, Replacement:=" ")
Globals.ThisAddIn.Application.Selection.replace(What:=vbCrLf, Replacement:=" ")
Globals.ThisAddIn.Application.ScreenUpdating = True
Globals.ThisAddIn.Application.DisplayAlerts = True
However - I started coming across line feeds that weren't being removed by that code. After playing with it a bit, I ended up getting the ASCII codes for the line feeds I couldn't remove.
I then altered my code to this:
Code:
Globals.ThisAddIn.Application.ScreenUpdating = False
Globals.ThisAddIn.Application.DisplayAlerts = False
Globals.ThisAddIn.Application.Selection.replace(What:=vbNewLine, Replacement:=" ")
Globals.ThisAddIn.Application.Selection.replace(What:=vbCr, Replacement:=" ")
Globals.ThisAddIn.Application.Selection.replace(What:=vbLf, Replacement:=" ")
Globals.ThisAddIn.Application.Selection.replace(What:=vbCrLf, Replacement:=" ")
Globals.ThisAddIn.Application.Selection.replace(What:=Chr(10), Replacement:=" ")
Globals.ThisAddIn.Application.Selection.replace(What:=Chr(1), Replacement:=" ")
Globals.ThisAddIn.Application.Selection.replace(What:=Chr(3), Replacement:=" ")
Globals.ThisAddIn.Application.Selection.replace(What:=Chr(13), Replacement:=" ")
Globals.ThisAddIn.Application.ScreenUpdating = True
Globals.ThisAddIn.Application.DisplayAlerts = True
This works fabulously, however it replaces all 10's, 1's, 3's, and 13's with a space as well...which is bad.
Does anyone know how I can prevent the code from replacing the numbers?
Jun 11th, 2010, 08:36 AM
#2
Re: Removing Line Feeds - Excel
Remove the line
Code:
Globals.ThisAddIn.Application.Selection.replace(What:=Chr(1), Replacement:=" ")
See the AscII table link in my signature...
A good exercise for the Heart is to bend down and help another up...
Please Mark your Thread " Resolved", if the query is solved
MyGear :
★ CPU ★ Ryzen 5 5800X
★ GPU ★ NVIDIA GeForce RTX 3080 TI Founder Edition
★ RAM ★ G. Skill Trident Z RGB 32GB 3600MHz
★ MB ★ ASUS TUF GAMING X570 (WI-FI) ATX Gaming
★ Storage ★ SSD SB-ROCKET-1TB + SEAGATE 2TB Barracuda IHD
★ Cooling ★ NOCTUA NH-D15 CHROMAX BLACK 140mm + 10 of Noctua NF-F12 PWM
★ PSU ★ ANTEC HCG-1000-EXTREME 1000 Watt 80 Plus Gold Fully Modular PSU
★ Case ★ LIAN LI PC-O11 DYNAMIC XL ROG (BLACK) (G99.O11DXL-X)
★ Monitor ★ LG Ultragear 27" 240Hz Gaming Monitor
★ Keyboard ★ TVS Electronics Gold Keyboard
★ Mouse ★ Logitech G502 Hero
Jun 11th, 2010, 08:38 AM
#3
Thread Starter
Hyperactive Member
Re: Removing Line Feeds - Excel
I did it, and it no longer removes 1's (or 3's as i took that line out as well), but it still removes 10's and 13's...
Jun 11th, 2010, 08:40 AM
#4
Re: Removing Line Feeds - Excel
Show me the sample text in a cell...
A good exercise for the Heart is to bend down and help another up...
Please Mark your Thread " Resolved", if the query is solved
MyGear :
★ CPU ★ Ryzen 5 5800X
★ GPU ★ NVIDIA GeForce RTX 3080 TI Founder Edition
★ RAM ★ G. Skill Trident Z RGB 32GB 3600MHz
★ MB ★ ASUS TUF GAMING X570 (WI-FI) ATX Gaming
★ Storage ★ SSD SB-ROCKET-1TB + SEAGATE 2TB Barracuda IHD
★ Cooling ★ NOCTUA NH-D15 CHROMAX BLACK 140mm + 10 of Noctua NF-F12 PWM
★ PSU ★ ANTEC HCG-1000-EXTREME 1000 Watt 80 Plus Gold Fully Modular PSU
★ Case ★ LIAN LI PC-O11 DYNAMIC XL ROG (BLACK) (G99.O11DXL-X)
★ Monitor ★ LG Ultragear 27" 240Hz Gaming Monitor
★ Keyboard ★ TVS Electronics Gold Keyboard
★ Mouse ★ Logitech G502 Hero
Jun 11th, 2010, 08:42 AM
#5
Thread Starter
Hyperactive Member
Re: Removing Line Feeds - Excel
See the attached.
The text "P 0011349" changes to "P 001 49".
Attached Images
Jun 11th, 2010, 08:45 AM
#6
Re: Removing Line Feeds - Excel
Well I just tried the same text in my excel sheet and it didn't remove any 1 or 3
Can I see a sample worksheet with data as in your last post...
A good exercise for the Heart is to bend down and help another up...
Please Mark your Thread " Resolved", if the query is solved
MyGear :
★ CPU ★ Ryzen 5 5800X
★ GPU ★ NVIDIA GeForce RTX 3080 TI Founder Edition
★ RAM ★ G. Skill Trident Z RGB 32GB 3600MHz
★ MB ★ ASUS TUF GAMING X570 (WI-FI) ATX Gaming
★ Storage ★ SSD SB-ROCKET-1TB + SEAGATE 2TB Barracuda IHD
★ Cooling ★ NOCTUA NH-D15 CHROMAX BLACK 140mm + 10 of Noctua NF-F12 PWM
★ PSU ★ ANTEC HCG-1000-EXTREME 1000 Watt 80 Plus Gold Fully Modular PSU
★ Case ★ LIAN LI PC-O11 DYNAMIC XL ROG (BLACK) (G99.O11DXL-X)
★ Monitor ★ LG Ultragear 27" 240Hz Gaming Monitor
★ Keyboard ★ TVS Electronics Gold Keyboard
★ Mouse ★ Logitech G502 Hero
Jun 11th, 2010, 08:47 AM
#7
Thread Starter
Hyperactive Member
Re: Removing Line Feeds - Excel
Attached.
If it makes a difference at all, I'm not doing this from VBA - I'm doing it from Visual Studio 2008.
Attached Files
Last edited by fEtchboi88; Jun 11th, 2010 at 08:48 AM .
Reason: Attachment
Jun 11th, 2010, 08:48 AM
#8
Re: Removing Line Feeds - Excel
I'm doing it from Visual StudioVisual Studio 2008.
Ah Ok... Let me see if it makes any difference...
BTW where is the attachment?
A good exercise for the Heart is to bend down and help another up...
Please Mark your Thread " Resolved", if the query is solved
MyGear :
★ CPU ★ Ryzen 5 5800X
★ GPU ★ NVIDIA GeForce RTX 3080 TI Founder Edition
★ RAM ★ G. Skill Trident Z RGB 32GB 3600MHz
★ MB ★ ASUS TUF GAMING X570 (WI-FI) ATX Gaming
★ Storage ★ SSD SB-ROCKET-1TB + SEAGATE 2TB Barracuda IHD
★ Cooling ★ NOCTUA NH-D15 CHROMAX BLACK 140mm + 10 of Noctua NF-F12 PWM
★ PSU ★ ANTEC HCG-1000-EXTREME 1000 Watt 80 Plus Gold Fully Modular PSU
★ Case ★ LIAN LI PC-O11 DYNAMIC XL ROG (BLACK) (G99.O11DXL-X)
★ Monitor ★ LG Ultragear 27" 240Hz Gaming Monitor
★ Keyboard ★ TVS Electronics Gold Keyboard
★ Mouse ★ Logitech G502 Hero
Jun 11th, 2010, 08:49 AM
#9
Thread Starter
Hyperactive Member
Re: Removing Line Feeds - Excel
Didn't realize you can't attach xls's - i zipped and attached to last post.
Thanks a ton man.
Jun 11th, 2010, 08:55 AM
#10
Re: Removing Line Feeds - Excel
Ok I tried in VBA and I didn't see the ones and three's getting deleted...
If I am not wrong, in vb.net you have something like Convert.ToChar(Int32) in System.Convert class. Let me check and get back to you...
Edit:
Also check this for me. One by one remove the line having CHR() and see including which line is giving you the trouble
Last edited by Siddharth Rout; Jun 11th, 2010 at 09:00 AM .
A good exercise for the Heart is to bend down and help another up...
Please Mark your Thread " Resolved", if the query is solved
MyGear :
★ CPU ★ Ryzen 5 5800X
★ GPU ★ NVIDIA GeForce RTX 3080 TI Founder Edition
★ RAM ★ G. Skill Trident Z RGB 32GB 3600MHz
★ MB ★ ASUS TUF GAMING X570 (WI-FI) ATX Gaming
★ Storage ★ SSD SB-ROCKET-1TB + SEAGATE 2TB Barracuda IHD
★ Cooling ★ NOCTUA NH-D15 CHROMAX BLACK 140mm + 10 of Noctua NF-F12 PWM
★ PSU ★ ANTEC HCG-1000-EXTREME 1000 Watt 80 Plus Gold Fully Modular PSU
★ Case ★ LIAN LI PC-O11 DYNAMIC XL ROG (BLACK) (G99.O11DXL-X)
★ Monitor ★ LG Ultragear 27" 240Hz Gaming Monitor
★ Keyboard ★ TVS Electronics Gold Keyboard
★ Mouse ★ Logitech G502 Hero
Jun 11th, 2010, 08:59 AM
#11
Thread Starter
Hyperactive Member
Re: Removing Line Feeds - Excel
New Code (still doesn't work):
Code:
Globals.ThisAddIn.Application.ScreenUpdating = False
Globals.ThisAddIn.Application.DisplayAlerts = False
Globals.ThisAddIn.Application.Selection.replace(What:=vbNewLine, Replacement:=" ")
Globals.ThisAddIn.Application.Selection.replace(What:=vbCr, Replacement:=" ")
Globals.ThisAddIn.Application.Selection.replace(What:=vbLf, Replacement:=" ")
Globals.ThisAddIn.Application.Selection.replace(What:=vbCrLf, Replacement:=" ")
Globals.ThisAddIn.Application.Selection.replace(What:=Convert.ToChar(10), Replacement:=" ")
Globals.ThisAddIn.Application.Selection.replace(What:=Convert.ToChar(13), Replacement:=" ")
Globals.ThisAddIn.Application.ScreenUpdating = True
Globals.ThisAddIn.Application.DisplayAlerts = True
Jun 11th, 2010, 09:01 AM
#12
Re: Removing Line Feeds - Excel
Check this for me. One by one remove the line having CHR() and see including which line is giving you the trouble... Is it the 10 or the 13?
A good exercise for the Heart is to bend down and help another up...
Please Mark your Thread " Resolved", if the query is solved
MyGear :
★ CPU ★ Ryzen 5 5800X
★ GPU ★ NVIDIA GeForce RTX 3080 TI Founder Edition
★ RAM ★ G. Skill Trident Z RGB 32GB 3600MHz
★ MB ★ ASUS TUF GAMING X570 (WI-FI) ATX Gaming
★ Storage ★ SSD SB-ROCKET-1TB + SEAGATE 2TB Barracuda IHD
★ Cooling ★ NOCTUA NH-D15 CHROMAX BLACK 140mm + 10 of Noctua NF-F12 PWM
★ PSU ★ ANTEC HCG-1000-EXTREME 1000 Watt 80 Plus Gold Fully Modular PSU
★ Case ★ LIAN LI PC-O11 DYNAMIC XL ROG (BLACK) (G99.O11DXL-X)
★ Monitor ★ LG Ultragear 27" 240Hz Gaming Monitor
★ Keyboard ★ TVS Electronics Gold Keyboard
★ Mouse ★ Logitech G502 Hero
Jun 11th, 2010, 09:03 AM
#13
Thread Starter
Hyperactive Member
Jun 11th, 2010, 09:13 AM
#14
Re: Removing Line Feeds - Excel
What does this give you?
Code:
Msgbox Convert.ToChar(10)
Msgbox Convert.ToChar(13)
A good exercise for the Heart is to bend down and help another up...
Please Mark your Thread " Resolved", if the query is solved
MyGear :
★ CPU ★ Ryzen 5 5800X
★ GPU ★ NVIDIA GeForce RTX 3080 TI Founder Edition
★ RAM ★ G. Skill Trident Z RGB 32GB 3600MHz
★ MB ★ ASUS TUF GAMING X570 (WI-FI) ATX Gaming
★ Storage ★ SSD SB-ROCKET-1TB + SEAGATE 2TB Barracuda IHD
★ Cooling ★ NOCTUA NH-D15 CHROMAX BLACK 140mm + 10 of Noctua NF-F12 PWM
★ PSU ★ ANTEC HCG-1000-EXTREME 1000 Watt 80 Plus Gold Fully Modular PSU
★ Case ★ LIAN LI PC-O11 DYNAMIC XL ROG (BLACK) (G99.O11DXL-X)
★ Monitor ★ LG Ultragear 27" 240Hz Gaming Monitor
★ Keyboard ★ TVS Electronics Gold Keyboard
★ Mouse ★ Logitech G502 Hero
Jun 11th, 2010, 09:18 AM
#15
Thread Starter
Hyperactive Member
Re: Removing Line Feeds - Excel
A blank msgbox (i'm assuming there are line feeds).
Jun 11th, 2010, 09:20 AM
#16
Re: Removing Line Feeds - Excel
Originally Posted by
fEtchboi88
A blank msgbox (i'm assuming there are line feeds).
Exactly, I was expecting what you got... so how does it find 10 or 13 and replace?
i am still trying to figure it out...
A good exercise for the Heart is to bend down and help another up...
Please Mark your Thread " Resolved", if the query is solved
MyGear :
★ CPU ★ Ryzen 5 5800X
★ GPU ★ NVIDIA GeForce RTX 3080 TI Founder Edition
★ RAM ★ G. Skill Trident Z RGB 32GB 3600MHz
★ MB ★ ASUS TUF GAMING X570 (WI-FI) ATX Gaming
★ Storage ★ SSD SB-ROCKET-1TB + SEAGATE 2TB Barracuda IHD
★ Cooling ★ NOCTUA NH-D15 CHROMAX BLACK 140mm + 10 of Noctua NF-F12 PWM
★ PSU ★ ANTEC HCG-1000-EXTREME 1000 Watt 80 Plus Gold Fully Modular PSU
★ Case ★ LIAN LI PC-O11 DYNAMIC XL ROG (BLACK) (G99.O11DXL-X)
★ Monitor ★ LG Ultragear 27" 240Hz Gaming Monitor
★ Keyboard ★ TVS Electronics Gold Keyboard
★ Mouse ★ Logitech G502 Hero
Jun 11th, 2010, 09:22 AM
#17
Thread Starter
Hyperactive Member
Re: Removing Line Feeds - Excel
Ya - I'm thoroughly stumped. NOT a fan
Jun 11th, 2010, 09:28 AM
#18
Re: Removing Line Feeds - Excel
However - I started coming across line feeds that weren't being removed by that code.
I refuse to give up . Does the Excel sheet that you posted have any examples of the above?
A good exercise for the Heart is to bend down and help another up...
Please Mark your Thread " Resolved", if the query is solved
MyGear :
★ CPU ★ Ryzen 5 5800X
★ GPU ★ NVIDIA GeForce RTX 3080 TI Founder Edition
★ RAM ★ G. Skill Trident Z RGB 32GB 3600MHz
★ MB ★ ASUS TUF GAMING X570 (WI-FI) ATX Gaming
★ Storage ★ SSD SB-ROCKET-1TB + SEAGATE 2TB Barracuda IHD
★ Cooling ★ NOCTUA NH-D15 CHROMAX BLACK 140mm + 10 of Noctua NF-F12 PWM
★ PSU ★ ANTEC HCG-1000-EXTREME 1000 Watt 80 Plus Gold Fully Modular PSU
★ Case ★ LIAN LI PC-O11 DYNAMIC XL ROG (BLACK) (G99.O11DXL-X)
★ Monitor ★ LG Ultragear 27" 240Hz Gaming Monitor
★ Keyboard ★ TVS Electronics Gold Keyboard
★ Mouse ★ Logitech G502 Hero
Jun 11th, 2010, 09:42 AM
#19
Thread Starter
Hyperactive Member
Re: Removing Line Feeds - Excel
OOOOOK - I swear to god those line feeds wouldn't remove with my original code, but I just tried it again and it worked without the added CHR lines. So I guess crisis averted?
Thanks for your help!
Jun 11th, 2010, 09:45 AM
#20
Re: [RESOLVED] Removing Line Feeds - Excel
lolzzzz... Gald it is resolved.
I had gone through every cell but couldn't see any strange line feeds...
A good exercise for the Heart is to bend down and help another up...
Please Mark your Thread " Resolved", if the query is solved
MyGear :
★ CPU ★ Ryzen 5 5800X
★ GPU ★ NVIDIA GeForce RTX 3080 TI Founder Edition
★ RAM ★ G. Skill Trident Z RGB 32GB 3600MHz
★ MB ★ ASUS TUF GAMING X570 (WI-FI) ATX Gaming
★ Storage ★ SSD SB-ROCKET-1TB + SEAGATE 2TB Barracuda IHD
★ Cooling ★ NOCTUA NH-D15 CHROMAX BLACK 140mm + 10 of Noctua NF-F12 PWM
★ PSU ★ ANTEC HCG-1000-EXTREME 1000 Watt 80 Plus Gold Fully Modular PSU
★ Case ★ LIAN LI PC-O11 DYNAMIC XL ROG (BLACK) (G99.O11DXL-X)
★ Monitor ★ LG Ultragear 27" 240Hz Gaming Monitor
★ Keyboard ★ TVS Electronics Gold Keyboard
★ Mouse ★ Logitech G502 Hero
Jun 11th, 2010, 09:46 AM
#21
Thread Starter
Hyperactive Member
Re: [RESOLVED] Removing Line Feeds - Excel
Just kidding - I lied.
It's still not working...the attached contains the line feeds that wont go away.
Attached Files
Jun 11th, 2010, 09:51 AM
#22
Thread Starter
Hyperactive Member
Re: [RESOLVED] Removing Line Feeds - Excel
I'm really confused now.
I opened the sheet I just attached, and ran the utility, and it did not work.
I put the 10 & 13 lines back in, and it worked, but removed the 10s and 13s.
I took the 10 & 13 lines back out, and tried it again, and it worked (and didn't remove the 10s and 13s). But it's still not working on the original spreadsheet.
I'm BAFFLED.
Jun 11th, 2010, 09:55 AM
#23
Jun 11th, 2010, 09:57 AM
#24
Thread Starter
Hyperactive Member
Re: [RESOLVED] Removing Line Feeds - Excel
Ya - IDK. Now it's working on the original spreadsheet, too, so it had to be formatting or something. I thought maybe because it was an .xlsx it wasn't working, but now it's working for that too.
Let's save us both a headache and not look into it anymore haha.
Thanks!!
Posting Permissions
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
Forum Rules
Click Here to Expand Forum to Full Width