+ Reply to Thread
Results 1 to 6 of 6

Complex math - language issue

Hybrid View

  1. #1
    Registered User
    Join Date
    05-14-2010
    Location
    Horsens, Denmark
    MS-Off Ver
    Excel 2003
    Posts
    4

    Complex math - language issue

    Hi all.

    I hope someone can help me out with the problem described here.

    I've discovered that the complex math in Excel is badly implemented, since in english and danish, the different names means that the complex math stops working. For example we have:

    English: IMSUB
    Danish: IMAGSUB

    and

    English: IMPRODUCT
    Danish: IMAGPRODUKT

    If I create the spreadsheet in danish, it doesn't work in english version of Excel.

    I thought I'd make a macro, which could search/replace these text strings. I'd place a
    button and the user could choose language him-/herself. Just started looking into macros two days ago.

    First I did a macro recording, which didn't continue to work. Simply because when I did the search/replace, the macro "forgets" to choose the entire workbook. It only searches the active sheet.

    I continued by putting the words I want to search/replace into some cells. They are placed in Sheet "DK" in cell range B104-C104 as you can see below.

    I coded the following:

    Sub ToEnglish()
    '
    ' ToEnglish Makro
    ' Makro indspillet 13-05-2010 af Claus Futtrup
    '
    
    '
        SaveActSheet = ActiveSheet.Name
        DK1 = Sheets("DK").Range("C103").Value
        DK2 = Sheets("DK").Range("C104").Value
        EN1 = Sheets("DK").Range("B103").Value
        EN2 = Sheets("DK").Range("B104").Value
        Sheets("5.47").Select
        Cells.Replace What:=DK1, Replacement:=EN1, LookAt:=xlPart, _
            SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
            ReplaceFormat:=False
        Cells.Replace What:=DK2, Replacement:=EN2, LookAt:= _
            xlPart, SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
            ReplaceFormat:=False
        Sheets(SaveActSheet).Select
    End Sub
    Sub ToDanish()
    '
    ' ToDanish Makro
    ' Makro indspillet 13-05-2010 af Claus Futtrup
    '
    
    '
        SaveActSheet = ActiveSheet.Name
        DK1 = Sheets("DK").Range("C103").Value
        DK2 = Sheets("DK").Range("C104").Value
        EN1 = Sheets("DK").Range("B103").Value
        EN2 = Sheets("DK").Range("B104").Value
        Sheets("5.47").Select
        Cells.Replace What:=EN1, Replacement:=DK1, LookAt:= _
            xlPart, SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
            ReplaceFormat:=False
        Cells.Replace What:=EN2, Replacement:=DK2, LookAt:=xlPart, _
            SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
            ReplaceFormat:=False
        Sheets(SaveActSheet).Select
    End Sub
    Unfortunately the macro doesn't find anything to replace ... I am at a loss here. Running "BREAK" and "WATCH" the expressions DK1 and EN1 (stepping through the macro with F5) I can see that they stay empty ...

    Please help me accomplish what I'd like to do.

    Best regards,
    Claus

  2. #2
    Forum Expert davegugg's Avatar
    Join Date
    12-18-2008
    Location
    WI, US
    MS-Off Ver
    2010
    Posts
    1,884

    Re: Complex math - language issue

    Maybe you could use the built-in find/replace function to just change those functions in the formulas in your cells:

    Sub cfuttrup()
    
    Dim ws As Worksheet
    
    For Each ws In ActiveWorkbook.Sheets
        ws.Cells.Replace What:="IMSUB", Replacement:="IMAGSUM", LookAt:=xlPart, _
            SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
            ReplaceFormat:=False
        ws.Cells.Replace What:="IMPRODUCT", Replacement:="IMAGPRODUKT", LookAt:=xlPart, _
            SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
            ReplaceFormat:=False
    Next ws
    
    End Sub
    Is your code running too slowly?
    Does your workbook or database have a bunch of duplicate pieces of data?
    Have a look at this article to learn the best ways to set up your projects.
    It will save both time and effort in the long run!


    Dave

  3. #3
    Registered User
    Join Date
    05-14-2010
    Location
    Horsens, Denmark
    MS-Off Ver
    Excel 2003
    Posts
    4

    Re: Complex math - language issue

    Hi Dave.

    Thanks. Your version works. It also seems relatively simple.

    Is there any way in which I can change the "fixed" strings (IMAGSUB, IMSUB) into variables that I can load from some cells in the spreadsheet? I attempted to do that - just so that e.g. a German (or e.g. French) user could substitute the danish complex math functions for their own language ditto ...

    Best regards,
    Claus

  4. #4
    Forum Expert davegugg's Avatar
    Join Date
    12-18-2008
    Location
    WI, US
    MS-Off Ver
    2010
    Posts
    1,884

    Re: Complex math - language issue

    Yes, you can replace them with cells on a sheet, or you could use input boxes so the user types them directly.

    Sub cfuttrup()
    
    Dim ws As Worksheet
    Dim str1 As String
    Dim str2 As String
    Dim str3 As String
    Dim str4 As String
    
    str1 = Sheets("Sheet Name").Cells(1, "A").Value
    str2 = Sheets("Sheet Name").Cells(1, "B").Value
    str3 = InputBox("Enter the text to replace.")
    str4 = InputBox("Enter the replacement text.")
    
    For Each ws In ActiveWorkbook.Sheets
        ws.Cells.Replace What:=str1, Replacement:=str2, LookAt:=xlPart, _
            SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
            ReplaceFormat:=False
        ws.Cells.Replace What:=str3, Replacement:=str4, LookAt:=xlPart, _
            SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
            ReplaceFormat:=False
    Next ws
    
    End Sub
    Examples of each is shown in the code above.

  5. #5
    Valued Forum Contributor squiggler47's Avatar
    Join Date
    02-17-2009
    Location
    Littleborough, UK
    MS-Off Ver
    Excel 3.0 to 2007+2010! (couldnt get 2.1 working)
    Posts
    1,013

    Re: Complex math - language issue

    Thats interesting, I thought that excel files used a token system in <2007 versions, which would mean the function names should automatically convert between languages!
    Regards
    Darren

    Update 12-Nov-2010 Still job hunting!

    If you are happy with the results, please add to our reputation by clicking the blue scales icon in the blue bar of the post.

    Learn something new each day, Embrace change do not fear it, evolve and do not become extinct!


  6. #6
    Registered User
    Join Date
    05-14-2010
    Location
    Horsens, Denmark
    MS-Off Ver
    Excel 2003
    Posts
    4

    Re: Complex math - language issue

    Dear davegugg

    Thank you very much for your help. I seem to run into the "missing defining the variable" ... because other code examples doesn't show this part. Your examples are most helpful.

    Dear squiggler47

    Yes it is interesting that complex math doesn't convert ... it's only a problem with the complex functions (which are activated by enabling Analysis ToolPak), AFAIK.

    Best regards,
    Claus

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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