Long story short.
Windows 10.
Office 2013/2016
Document is exported from other system.
Cell contains hyper link with lets says "105,000" the other same is custom setting 105,000(#.###)
In this case "," represent thousands.
Client download report. Here is where regional settings and excel settings hit in.
Custom setting is converted to 105.000 but hyperlink "105,000" stays the same.(in this case "," means decimal. Should be converted to thousands)
Client claims it worked on windows 7.
Any ideas?
In general, whenever something like this happens with me in Excel I try one of these:
In Excel - =Replace(TheHyperlink,",",".")
With VBA - =fnStrChangeCommas(TheHyperlink)
Public Function fnStrChangeCommas(ByVal myValue As Variant) As String
fnStrChangeCommas = Replace(CStr(myValue), ",", ".")
End Function
Related
I hope someone will be able to help me sort this one out because I've been crawling the Internet for some time now and could not find any obvious reason why the behavior of my macro under Excel works for some users (including me of course) and does not work on some other users' laptops.
My objective:
Write from a VBA SubRoutine a vlookup formula in one cell. Based on that vlookup, either it finds something and it displays a text A or the vlookup throws an error and it then displays a text B.
The situation
Here is the formula if we were writing it directly in the sheet from the end-user's perspective: =IF(NOT(ISERROR(VLOOKUP(C2,DataSet2!$A$2:$A$12,1,0))),"Direct Report","Team member of direct report")
When we copy/paste that formula on a PC where the macro fails directly in the spreadsheet. It works.
When we run the macro actually trying to incorporate that formula in that exact same cell, it fails and throws an error 400.
Here is now the VBA code attempting to write the above formula in the cell:
formulaString = "=IF(NOT(ISERROR(VLOOKUP(C" & CStr(counter + 2) & systemListSeparator & "DataSet2!$A$2:$A$" & CStr(2 + totalDirectReportsCount) & systemListSeparator & "1" & systemListSeparator & "0)))" & systemListSeparator & """Direct Report""" & systemListSeparator & """Team member of direct report"")"
Selection.Offset(counter, 0).Formula = formulaString
So the above 2 statements, as you'll have understood probably, are included in a loop and for every single row I have, I want to add that formula in the first cell from the currently selected cell.
What drives me crazy is that: it works fine on my PC, it works fine on my colleague's PC who is in Finland, but on another colleague's PC also in Finland, it does not. I have Windows 10 and Office 2016, she has Windows 10 and office 2016 as well...
So I am really wondering if there could be some regional settings or Excel settings or System Settings which could make HER Excel not interpret my "formulaString" as viable for her laptop. I have made sure to fetch the list separator to avoid those usual regional settings easy traps but would there be other similar traps I am not aware of?
Thanks a lot for any hints I could follow to progress on my investigations.
Kind regards,
Nicolas C.
This is really a tricky point, but fortunately VBA provides an excellent solution.
Simply write the formula in Excel, select the cell and run the following code:
Public Sub TestMe()
With ActiveCell
Debug.Print .Formula
Debug.Print .FormulaLocal
Debug.Print .FormulaR1C1
End With
End Sub
In German Excel, this is what you would get:
=SUM(C1+D1)
=SUMME(C1+D1)
=SUM(RC[2]+RC[3])
Then rebuild your formulas, using only .Formula or .FormulaR1C1 and the result from the immediate window. Thus your colleagues from all over the world would be really happy. As noted in the 3 examples, the first and the third one always give the same answer, following the en_US format.
Another option is that Excel and VBA do not like your formula, because of the decimal separator in Finland, being different from the decimal separator in the USA. See How to add hardcoded float number values to the formula using VBA to change it a bit.
Solution
Nicolas C. edit: All the above comments and hereby answer have helped me solving my issue. Thank you very much guys for your prompt reaction and feedback. You really saved my day. So the root cause was indeed that I had tried to capture the end-user's system preferences on his/her locale and regional settings and making use of his/her list separator (which was ; actually) within the VBA script which was a bad move since, as mentioned by #AxelRichter and #Vityata, within a VBA script, .Formula needs always to be written in the en_US format, that is english function names, commas, etc.
I have now removed my user related list separator and replaced it with traditional commas and it solved my issue.
I am trying to make a customer link by concatenating two cells containing parts of the URL string, but for some reason it is not working.
These are the strings:
A1:
https://www.correosexpress.com/web/correosexpress/envios4?p_p_id=chxseguimientoEnviosPublico_WAR_chxseguimientoEnviosPublicoportlet&_chxseguimientoEnviosPublico_WAR_chxseguimientoEnviosPublicoportlet_struts.portlet.action=/view/getShippingPublic_execute&_chxseguimientoEnviosPublico_WAR_chxseguimientoEnviosPublicoportlet_shippingNumber=
A2:
(Number we will add in each custom link)
A3: &_chxseguimientoEnviosPublico_WAR_chxseguimientoEnviosPublicoportlet_zipCode=
A4: (number we will add in each customer link)
I am trying the following and receiving an error every time:
=HYPERLINK(CONCATENATE(A1:A2:A3:A4);[LINK])
I tried adding text instead of A1 but the string is too long (more than 255 characters).
I have hit the 255 character limit several times, and unfortunately there is no way around it. You can work around this with VBA, or you can shorten the url in A1 using something like goo.gl url shortener, and then concatenate.
Try this instead:
=HYPERLINK("CONCATENATE(A1,A2,A3,A4)","[LINK]")
NOTE: I put commas instead of colons and semicolons, but you may need to change them back where you are.
I needed to send some data to a PHP-Script and i needed to work on windows and osx.
After some reasearch and trying i ended up with this visual basic function:
Sub SendImportData()
Dim URL As String
URL = "https://example.com/import.php?" & Range("M1").Value
Open "temporary.url" For Output As #1
Print #1, "[InternetShortcut]"
Print #1, "URL=" & URL
Close #1
Shell "temporary.url"
End Sub
Then i built the querystring in excel itself (M1). But you can also built it within visual basic. This will give you more flexibility.
I also want to mention that you need to url-encode the values in your querystring.
There is still a limit of how long a url can be in different browsers. But its much higher than the excel limit.
Hope i could help someone.
Ever since i added a multiple language option for my computer, Excel decided to turn all my decimals into commas. I need to turn them back into decimals again. How do i do this with least amount of work? If you know an EASY way to do this, emphasis on easy, please tell. When it is converted, i need a number, not text or anything else. I'm using Microsoft Office Professional Plus 2010.
I tried the approach where you make this formula in Excel
=SUBSTITUTE(A4;",";".")+0
Which should, i'm assuming, get cell A4, change comma into period and then by adding 0 convert to number. My original number is 17.6, now i'm getting 41807.
My best choice to use the below function which can help to convert the text to numbers also at the same time. Its very useful in cases where some systme reports are shared with different number formats
=NUMBERVALUE(SUBSTITUTE(SUBSTITUTE(E3,".",""),",","."))
There're two options for you.
1) change regional settings on your PC:
2) use Application.DecimalSeparator in VBA code (e.g. in Workbook_Open event):
Private Sub Workbook_Open()
Application.DecimalSeparator = "."
End Sub
I developed an Access database solution that is using Excel automation to open xls and xlsx files so I can import specific cells that I need.
Now I had to deploy my software to an user that does not have Office nor Excel installed and is using Runtime do run my program and I can not use automation any more.
Is there any way I can open an Excel file without Excel and import lets say cell B7 and cell E4 ? I dont need to import it in the table directly but to operate with results from xls in the memory (as I did with Excel object) and save it later.
Thanks in advance.
With some (quite severe) limitations, it is possible to use Jet (i.e., the Access database engine, an ageing version of which is a standard Windows component) to read XLS files at least. For the limitations see here:
http://support.microsoft.com/kb/257819/en-gb
As for an example...
Function ReadCell(XLSFileName As String, SheetName As String, CellName As String)
Dim DB As DAO.Database, RS As DAO.Recordset
Set DB = DBEngine.OpenDatabase(XLSFileName, False, True, "Excel 8.0;HDR=No;")
Set RS = DB.OpenRecordset("SELECT * FROM [" + SheetName + "$" + CellName + ":" + CellName "]")
ReadCell = RS(0)
RS.Close
DB.Close
End Function
Sub Foo
MsgBox ReadCell("C:\Users\ExeBat\Documents\Test.xls", "Summary Details", "C5")
End Sub
My guess is not without a 3rd party library of some sort. Potentially you could read the file as text if it was stored as office open XML, my guess is that MS encrypts/obfuscates your standard xls/xlsx file by default so you cannot though. If Excel isn't available on your user machines in all cases you might need to look into having the source data in another format (text, csv, etc), I know that is probably not an ideal answer though.
I have found many blocks of code that containVBA.Date, for example;
Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Column <> 2 Then Exit Sub
Target.Offset(0, 1).Value = Format(VBA.Date, “MM/DD/YYYY”)
End Sub
Or
Sub YearSheets()
Dim i As Integer
i = 0
Do
Sheets.Add(After:=Sheets(Sheets.Count)).Name = Format(VBA.Date + i, “MM-DD-YYYY”)
i = i + 1
Loop Until i = 365
End Sub
I have tried these steps:
I have pushed F1 for VBA's help but it shows "Keyword Not Found".
Searched my VBA books but no one shows something because they take such a piece of information as unimportant or too easy (I guess).
I have tried to Google it --> You can imagine what happens with a combination of such common words.
I have pushed F2 in the VBE Window and opened the Object Browser
i. I searched for VBA and I got the library ... not very bright
ii. I searched for the Date Property and I found it to be preceded by the DateTime Module and going more in seniority from the VBA Library.
Question-born-from-question: Is it possible to be the VBA library here VBA.Date?
Frustrating-thing-that-happens: Once I type VBE IntelliSense shows Date Property, so it's hard-coded somewhere in my machine.
What really is VBA.Date - an object, a library that can be entered as as object?
Date() and Time() are Properties of the DateTime Class. Found in Excel VBA. They are of DataType Variant that contain the current system date when Date is used and current system time when Time is used.
They do not need to be preceeded by the VBA or the DateTime in order to be used they can simply be used with the terms Date, and Time.
Date, and if the calendar is Gregorian, Date$ behavior is unchanged by the Calendar property setting. If the calendar is Hijri, Date$ returns a 10-character string of the form mm-dd-yyyy, where mm (01-12), dd (01-30) and yyyy (1400-1523) are the Hijri month, day and year. The equivalent Gregorian range is Jan 1, 1980 through Dec 31, 2099.
In the future the best way to get information on specific function, properties, methods, classes and other members of the VBA Language you can use the Object Browser.
Marked one is the object browser and when clicked on will open this window (it can also be accessed with pressing F2) In this window enter what you are searching for
One you get results scroll through and look for a more specific item:
Now there are 2 points in the above image:
1) At the bottom of the screen it gives basic detail about this item, in this case
it states that it belongs to the `DateTime` Class, and is a property of that
class, and that it is a Variant.
2) Also in the picture above I have right clicked on the item and selected Help from
the context menu, this will bring up even more details about this item.
As you can see here Microsoft has built in support for this item and gives you details on what it is, what data type it would use and what it returns. Also, how to use and some common notes for when you use it!
VBA.Date and VBA.Time are functions that return the current date and the current time, respectively.
In your editor Tools / References you'll see 'Visual Basic For Applications' is selected. I have absoutely no proof but my idle conjecture is that this is where your VBA.Date (and VBA, everything) lies. Furthermore your F2 investigations show you the truth - It's in the VBA module there. Note you can use VBA.Date or just Date and they are the same thing.
In short it's hard coded in that DLL file referred to in Tools/References.