+ Reply to Thread
Results 1 to 36 of 36

Formula in a macro doesnt work for Spanish Excel user

  1. #1
    Registered User
    Join Date
    01-03-2013
    Location
    Indiana, US
    MS-Off Ver
    Microsoft 365
    Posts
    26

    Formula in a macro doesnt work for Spanish Excel user

    Not sure if this is a formula question, a Macro question or an Excel question.
    I have a macro that I wrote that will not work when I share it with a co-worker who's excel is in Spanish. The line of code takes the date that is written "W43-2018\22th October" and translates it to "10/22/2018". The Macro code is :
    ActiveCell.FormulaR1C1 = "=DATE((MID(R[-1]C,5,4)),(MONTH((DATEVALUE(MID(R[-1]C,FIND(""th"",R[-1]C,1)+3,LEN(R[-1]C)-(FIND(""th"",R[-1]C,1)+3-1)))))),(MID(R[-1]C,10,(FIND(""th"",R[-1]C,1)-1-10)+1)))"

    which enters this formula:
    "=DATE((MID(D1,5,4)),(MONTH((DATEVALUE(MID(D1,FIND("th",D1,1)+3,LEN(D1)-(FIND("th",D1,1)+3-1)))))),(MID(D1,10,(FIND("th",D1,1)-1-10)+1)))"

    but when the middle part "MONTH((DATEVALUE(MID(D1,FIND("th",D1,1)+3,LEN(D1)-(FIND("th",D1,1)+3-1))&1)))" returns October, the Spanish user gets an error. This works fine for all English users. We tried switching her language to English to run it and we got the same issues. any idea how to fix this? We cannot change the way the date comes in (W43-2018\22th October) either.

  2. #2
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS365 Family 64-bit
    Posts
    24,705

    Re: Formula in a macro doesnt work for Spanish Excel user

    I am getting an error with that formula, using your example date string, before I even try to do anything in VBA. The fragment that you called "middle part" works for me but does not match the formula above it (it adds "&1" in the middle).

    Is there some reason that you want to insert a formula using VBA, instead of just calculating the date in VBA?

    nburton=Capture.JPG
    Jeff
    | | |會 |會 |會 |會 | |:| | |會 |會
    Read the rules
    Use code tags to [code]enclose your code![/code]

  3. #3
    Forum Expert Keebellah's Avatar
    Join Date
    01-12-2014
    Location
    The Netherlands
    MS-Off Ver
    Office 2021 (Windows)
    Posts
    7,905

    Re: Formula in a macro doesnt work for Spanish Excel user

    @nburton: text "th" is not Spanish, you cannot do it that way. your cell format is probably like that but that same format will not be the same on a Spanish system.
    You will have to agree an the way the data is displayed.
    Excel has no problems with languages as long as you don't use specific extra text. and October is Octubre in Spanish
    What is the excel numberformat for that cell where is says W43 etc.?
    ---
    Hans
    "IT" Always crosses your path!
    May the (vba) code be with you... if it isn't; start debugging!
    If you like my answer, Click the * below to say thank-you

  4. #4
    Registered User
    Join Date
    10-04-2018
    Location
    Cancun, Mexico
    MS-Off Ver
    2013 & 2016 32b
    Posts
    78

    Re: Formula in a macro doesnt work for Spanish Excel user

    the spanish formel for that is more or less like that :

    =FECHA((LARGO(D1,5,4)),(MES((FECHANUMERO(EXTRAE(D1,BUSCAR("th",D1,1)+3,LARGO(D1)-(BUSCAR("th",D1,1)+3-1)))))),(EXTRAE(D1,10,(BUSCAR("th",D1,1)-1-10)+1)))

  5. #5
    Forum Expert Keebellah's Avatar
    Join Date
    01-12-2014
    Location
    The Netherlands
    MS-Off Ver
    Office 2021 (Windows)
    Posts
    7,905

    Re: Formula in a macro doesnt work for Spanish Excel user

    @bluepomme: Yes but have YOU do not know what the actual cell content is for the Spanish user; have you checked that the cell content is actually written with the text 'th'?
    THAT is the question

  6. #6
    Registered User
    Join Date
    10-04-2018
    Location
    Cancun, Mexico
    MS-Off Ver
    2013 & 2016 32b
    Posts
    78

    Re: Formula in a macro doesnt work for Spanish Excel user

    TRUE ...

  7. #7
    Forum Expert Keebellah's Avatar
    Join Date
    01-12-2014
    Location
    The Netherlands
    MS-Off Ver
    Office 2021 (Windows)
    Posts
    7,905

    Re: Formula in a macro doesnt work for Spanish Excel user

    Ask that user to send you a screenshot of the worksheet

  8. #8
    Forum Guru
    Join Date
    03-02-2006
    Location
    Los Angeles, Ca
    MS-Off Ver
    WinXP/MSO2007;Win10/MSO2016
    Posts
    12,602

    Re: Formula in a macro doesnt work for Spanish Excel user

    Is it necessary for you to put a formula vs the date itself?
    Ben Van Johnson

  9. #9
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS365 Family 64-bit
    Posts
    24,705

    Re: Formula in a macro doesnt work for Spanish Excel user

    Quote Originally Posted by protonLeah View Post
    Is it necessary for you to put a formula vs the date itself?
    As in post #2. After seven responses we are still waiting for the return of the OP.

  10. #10
    Registered User
    Join Date
    01-03-2013
    Location
    Indiana, US
    MS-Off Ver
    Microsoft 365
    Posts
    26

    Re: Formula in a macro doesnt work for Spanish Excel user

    The date comes from the customer and can't be changed. My macro then takes the date and re-formats it to a usable format. I have no issues with moving the reformat to vb, I just don't know how.

  11. #11
    Registered User
    Join Date
    01-03-2013
    Location
    Indiana, US
    MS-Off Ver
    Microsoft 365
    Posts
    26

    Re: Formula in a macro doesnt work for Spanish Excel user

    Sorry if the code above was inaccurate, here it is:

    ActiveCell.FormulaR1C1 = "=DATE((MID(R[-1]C,5,4)),(MONTH((DATEVALUE(MID(R[-1]C,FIND(""th"",R[-1]C,1)+3,LEN(R[-1]C)-(FIND(""th"",R[-1]C,1)+3-1))&1)))),(MID(R[-1]C,10,(FIND(""th"",R[-1]C,1)-1-10)+1)))"

    Here's what the formula should come out as:
    =DATE((MID(D1,5,4)),(MONTH((DATEVALUE(MID(D1,FIND("th",D1,1)+3,LEN(D1)-(FIND("th",D1,1)+3-1))&1)))),(MID(D1,10,(FIND("th",D1,1)-1-10)+1)))

  12. #12
    Forum Expert Keebellah's Avatar
    Join Date
    01-12-2014
    Location
    The Netherlands
    MS-Off Ver
    Office 2021 (Windows)
    Posts
    7,905

    Re: Formula in a macro doesnt work for Spanish Excel user

    The problem still remains: How do YOU know the 'th' string is present in the file?
    This happens in your case or is it hard coded?
    What is the source's language setting and HOW doe is look on their side of Excel?
    You can keep on hammering on the fact tha the formula looks like this or that but for once give us a concrete answer.

  13. #13
    Registered User
    Join Date
    01-03-2013
    Location
    Indiana, US
    MS-Off Ver
    Microsoft 365
    Posts
    26

    Re: Formula in a macro doesnt work for Spanish Excel user

    10-29-2018 2-00-22 PM.jpg
    This is a screen shot of how it comes from the customer. There is always a "th" following the day of the month.

  14. #14
    Registered User
    Join Date
    01-03-2013
    Location
    Indiana, US
    MS-Off Ver
    Microsoft 365
    Posts
    26

    Re: Formula in a macro doesnt work for Spanish Excel user

    10-26-2018 10-32-05 AM.jpg

    This is what it looks like to her.

  15. #15
    Forum Guru
    Join Date
    03-02-2006
    Location
    Los Angeles, Ca
    MS-Off Ver
    WinXP/MSO2007;Win10/MSO2016
    Posts
    12,602

    Re: Formula in a macro doesnt work for Spanish Excel user

    You could put the below in a loop to process the column headers:
    Please Login or Register  to view this content.

  16. #16
    Forum Expert Keebellah's Avatar
    Join Date
    01-12-2014
    Location
    The Netherlands
    MS-Off Ver
    Office 2021 (Windows)
    Posts
    7,905

    Re: Formula in a macro doesnt work for Spanish Excel user

    Looks like a good macro.

  17. #17
    Registered User
    Join Date
    01-03-2013
    Location
    Indiana, US
    MS-Off Ver
    Microsoft 365
    Posts
    26

    Re: Formula in a macro doesnt work for Spanish Excel user

    I created the loop:
    Please Login or Register  to view this content.
    This worked great for me but the user got a type mismatch this is what her screen looked like after running:

    10-30-2018 3-12-49 PM.jpg
    Rows 3 and 4 were not in date format previously.
    Last edited by nburton; 10-30-2018 at 03:23 PM.

  18. #18
    Registered User
    Join Date
    01-03-2013
    Location
    Indiana, US
    MS-Off Ver
    Microsoft 365
    Posts
    26

    Re: Formula in a macro doesnt work for Spanish Excel user

    Last edited by nburton; 10-30-2018 at 03:22 PM.

  19. #19
    Forum Guru
    Join Date
    03-02-2006
    Location
    Los Angeles, Ca
    MS-Off Ver
    WinXP/MSO2007;Win10/MSO2016
    Posts
    12,602

    Re: Formula in a macro doesnt work for Spanish Excel user

    I don't understand. The only line that writes to the sheet is: Cells(2, i).Value = DV
    However, you have:

    Set sht = ThisWorkbook.Worksheets("Forecast")

    I don't know if you are running the code with some other sheet active. You might try:

    sht.Cells(2, i).Value = DV

  20. #20
    Registered User
    Join Date
    01-03-2013
    Location
    Indiana, US
    MS-Off Ver
    Microsoft 365
    Posts
    26

    Re: Formula in a macro doesnt work for Spanish Excel user

    I tried making that change and it still resulted in an error. I went through the Macro with her step by step through the Debugger and the line "DV = DateValue(DayNum & " " & Mnth & " " & Yr)" is the line that's causing it to fail. She's getting a type mismatch error. Any idea?


    11-1-2018 3-48-55 PM.jpg

  21. #21
    Forum Expert Keebellah's Avatar
    Join Date
    01-12-2014
    Location
    The Netherlands
    MS-Off Ver
    Office 2021 (Windows)
    Posts
    7,905

    Re: Formula in a macro doesnt work for Spanish Excel user

    Add a line to display the variable values:

    Before the line DV = ...


    Please Login or Register  to view this content.
    It's probably in one of those

    Another thing, no date separtor? Datevalue expects a string with the format

    Please Login or Register  to view this content.
    Last edited by Keebellah; 11-01-2018 at 04:09 PM.

  22. #22
    Forum Guru
    Join Date
    03-02-2006
    Location
    Los Angeles, Ca
    MS-Off Ver
    WinXP/MSO2007;Win10/MSO2016
    Posts
    12,602

    Re: Formula in a macro doesnt work for Spanish Excel user

    The attachment uses your macro loop. It's different from the screenshot you posted (?)
    Attached Files Attached Files

  23. #23
    Forum Expert Keebellah's Avatar
    Join Date
    01-12-2014
    Location
    The Netherlands
    MS-Off Ver
    Office 2021 (Windows)
    Posts
    7,905

    Re: Formula in a macro doesnt work for Spanish Excel user

    I am assuming that the Mnth is the variable that causes the problem.

  24. #24
    Registered User
    Join Date
    01-03-2013
    Location
    Indiana, US
    MS-Off Ver
    Microsoft 365
    Posts
    26

    Re: Formula in a macro doesnt work for Spanish Excel user

    ProtonLeah: I'm not sure what screenshot you are referring to, the only difference between the macro you attached and the code in the screen shot directly above is the "sht." before the Cells. I added that after the suggestion above.

    Keebellah: This is what showed up in the Intermediate window

    11-2-2018 11-20-34 AM.jpg

  25. #25
    Forum Expert rorya's Avatar
    Join Date
    08-13-2008
    Location
    East Sussex, UK
    MS-Off Ver
    365 Ent Monthly Channel / Insiders Beta
    Posts
    8,903

    Re: Formula in a macro doesnt work for Spanish Excel user

    Perhaps try:

    Please Login or Register  to view this content.
    Rory

  26. #26
    Forum Expert Keebellah's Avatar
    Join Date
    01-12-2014
    Location
    The Netherlands
    MS-Off Ver
    Office 2021 (Windows)
    Posts
    7,905

    Re: Formula in a macro doesnt work for Spanish Excel user

    The intermediate window, no errors when showing the results?

  27. #27
    Registered User
    Join Date
    01-03-2013
    Location
    Indiana, US
    MS-Off Ver
    Microsoft 365
    Posts
    26

    Re: Formula in a macro doesnt work for Spanish Excel user

    I got the same error, a type Mismatch and this is what printed to the Intermediate window.

  28. #28
    Forum Expert Keebellah's Avatar
    Join Date
    01-12-2014
    Location
    The Netherlands
    MS-Off Ver
    Office 2021 (Windows)
    Posts
    7,905

    Re: Formula in a macro doesnt work for Spanish Excel user

    Yes, and which item in the loop was giving the error?

  29. #29
    Forum Guru
    Join Date
    03-02-2006
    Location
    Los Angeles, Ca
    MS-Off Ver
    WinXP/MSO2007;Win10/MSO2016
    Posts
    12,602

    Re: Formula in a macro doesnt work for Spanish Excel user

    I was referring to the screen shot in post #17 that shows weird dates in rows 3 & 4 such as 16/08/3723. The macro does not write to those rows. Do the dates in row 1 such as D4 have English or Spanish month names? "October" or something esle?

  30. #30
    Registered User
    Join Date
    01-03-2013
    Location
    Indiana, US
    MS-Off Ver
    Microsoft 365
    Posts
    26

    Re: Formula in a macro doesnt work for Spanish Excel user

    Protonleah: Here's the full code,


    Please Login or Register  to view this content.
    This is what the customer incoming file looks like:

    11-2-2018 3-17-30 PM.jpg

    and this is what the output should look like:
    11-2-2018 3-20-26 PM.jpg

  31. #31
    Registered User
    Join Date
    01-03-2013
    Location
    Indiana, US
    MS-Off Ver
    Microsoft 365
    Posts
    26

    Re: Formula in a macro doesnt work for Spanish Excel user

    Keebellah: DV = DateValue(DayNum & " " & Mnth & " " & Yr) is the line of code that is making the macro error.

  32. #32
    Forum Contributor
    Join Date
    10-08-2018
    Location
    Lima, Peru
    MS-Off Ver
    Office 365 ProPlus
    Posts
    148

    Re: Formula in a macro doesnt work for Spanish Excel user

    =DATEVALUE(MID(D1,FIND("\",D1)+1,FIND(" ",D1)-FIND("\",D1)-3) &" " & MID(D1,FIND(" ",D1)+1,15)&MID(D1,FIND("\",D1)-4,4))
    Will always return VALUE error in any system other than English.

    The problem is the system locale, it's in Spanish, and you're parsing a month string "October", which has no meaning and can't be translated into a proper month number, as the string for Month 10 is "Octubre" in Spanish.

    SYSTEMLOCALE = Application.LanguageSettings.LanguageID(msoLanguageIDUI)
    Spanish locale is 1033, so you could do a:
    IF SYSTEMLOCALE = 1033
    CHANGE MONTH STRINGS FROM ENGLISH TO SPANISH: Enero, Febrero, Marzo... an so on

    Hope that helps a little.

  33. #33
    Forum Guru
    Join Date
    03-02-2006
    Location
    Los Angeles, Ca
    MS-Off Ver
    WinXP/MSO2007;Win10/MSO2016
    Posts
    12,602

    Re: Formula in a macro doesnt work for Spanish Excel user

    so:
    Please Login or Register  to view this content.
    Last edited by protonLeah; 11-02-2018 at 09:49 PM.

  34. #34
    Forum Contributor
    Join Date
    10-08-2018
    Location
    Lima, Peru
    MS-Off Ver
    Office 365 ProPlus
    Posts
    148

    Re: Formula in a macro doesnt work for Spanish Excel user

    As I said, translate to locale, or, you can create an array with your strings, and pull the month number directly from it...
    as protonLeah did:

    Quote Originally Posted by protonLeah View Post
    so:
    Please Login or Register  to view this content.


    This is a very nice aproach:

    Mnth = WorksheetFunction.Match(Temp(1), MoNames, 0) * 1

  35. #35
    Registered User
    Join Date
    01-03-2013
    Location
    Indiana, US
    MS-Off Ver
    Microsoft 365
    Posts
    26

    Re: Formula in a macro doesnt work for Spanish Excel user

    Sorry for the delay, I had to wait until I could test with the user. This worked perfectly! Thank you so much for all your help!

  36. #36
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS365 Family 64-bit
    Posts
    24,705

    Re: Formula in a macro doesnt work for Spanish Excel user

    If your question has been answered please mark your thread as "Solved" so that members will know by looking at the thread title that your problem is solved. Go to the menu immediately above your first post to the thread and click on Thread Tools. From the dropdown menu select "Mark this thread as solved..."

    If a member helped you solve your problem, consider adding to their reputation by clicking on the star icon addreputationiconsmall.jpg below their name.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Macro which used to work, now doesnt -
    By Spyros13 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 10-25-2016, 02:08 PM
  2. Macro copy doesnt work right
    By vindalloo77 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 08-23-2016, 08:34 AM
  3. Excel macro vba - hide specific colums doesnt work due to merged cell
    By kilaz17 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 12-21-2012, 11:24 AM
  4. My loop macro doesnt work
    By matdog in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 04-08-2010, 02:32 AM
  5. Replies: 2
    Last Post: 05-16-2006, 10:10 AM
  6. some functions doesnt work in macro?
    By ExcelPower in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 02-20-2006, 03:40 AM
  7. Please help : Macro doesnt work on other PCs
    By Jason in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 12-26-2005, 05:55 AM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1