Catching special Characters in vba

aidriiyan

New Member
Joined
May 12, 2010
Messages
7
The Macro I made requires 2 open workbook. 1st workbook is where it will automatically be filled up based on the contents of the 2nd workbook.
The macro will ask the name of the 2nd workbook then after clicking "ok", the 1st workbook will be filled with the data.

the name of the workbook is acquired using this:

wname = InputBox(Prompt:="Workbook name(do not include .xls):", _
Title:="CRYSTAL REPORT", Default:="workbook name here")

then it will be put in this code:

ActiveCell.FormulaR1C1 = _
"=IFERROR(VLOOKUP(RC[-1],[" & wname & ".xls" & "]Sheet1!R2C3:R60000C11,9,0),"""")"


The Problem: If wname(workbook name) consist of special characters, specifically open/close parenthesis, hypen.... the macro crashes because of error...

I tried using char(40), chr(41) ... but error again.
 

Excel Facts

Back into an answer in Excel
Use Data, What-If Analysis, Goal Seek to find the correct input cell value to reach a desired result
You need to enclose it within single quotes:

Code:
    wname = InputBox(Prompt:="Workbook name(do not include .xls):", Title:="CRYSTAL REPORT", Default:="workbook name here")
    ActiveCell.Formula = "=IFERROR(VLOOKUP(RC[-1],'[" & wname & ".xls" & "]Sheet1'!R2C3:R60000C11,9,0),"""")"
 
Upvote 0
Its not working sir.
Whenever I input names like,

CV(0-1) , 02-25-2010, 02_25_2010

It doesnt work.

but whenever I input names like

CrystalViewer or any names without symbols it works fine.
 
Upvote 0
This works perfectly.

The formula that comes out of it, is in my test setting:

=IFERROR(VLOOKUP(D5,'[CV(0-1).xls]Sheet1'!$C$2:$K$60000,9,0);"")

Wigi
 
Upvote 0
Before, even though I type that formula in excel(workbook names with special characters) I have no problem in executing it.

excel4.jpg


now ^ this is what happens.... That always opens...
 
Upvote 0
Anyway, for some reason... It finally works :D

The paranthesis, hypens and other special characters can now be catched.
Thank you very much :D

cool man :cool:
 
Upvote 0

Forum statistics

Threads
1,215,616
Messages
6,125,862
Members
449,266
Latest member
davinroach

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top