+ Reply to Thread
Results 1 to 17 of 17

Macro to find, replace text and calculate VAT in a cell

  1. #1
    Forum Contributor
    Join Date
    12-05-2008
    Location
    Germany
    MS-Off Ver
    365
    Posts
    568

    Macro to find, replace text and calculate VAT in a cell

    Dear All,

    please have a look at the attached workbook. Each sheet contains an Invoice. Each invoice has a cell containing "Totale ordine: EUR xx,xx".

    A macro should add the following to this cell content: after the amount, it should say "inc. EUR x,xx VAT 22%"

    I assume the first step is to find and replace the "Totale ordine: EUR" to have just a number in that cell so it can be calculated. This number should then be devided by 1,22 to get the net sum. The diffence between the total and the net amount is then the VAT amount. This amount should be inserted into the cell together with the above text.

    I hope this can be done with just one macro.

    Thanks muchly !!!

    Felix
    Attached Files Attached Files

  2. #2
    Forum Guru HaHoBe's Avatar
    Join Date
    02-19-2005
    Location
    Hamburg, Germany
    MS-Off Ver
    work: 2016 on Win10 (notebook), private: 2019 on Win10 (desktop), 2019 on Win11 (notebook)
    Posts
    8,197

    Re: Macro to find, replace text and calculate VAT in a cell

    Hi, Felix,

    maybe try:
    Please Login or Register  to view this content.
    Please mind that this macro will only run on the first try and not adapt values if they are changed as I didn´t see that as a requirement here.

    Ciao,
    Hiolger
    Use Code-Tags for showing your code: [code] Your Code here [/code]
    Please mark your question Solved if there has been offered a solution that works fine for you

  3. #3
    Forum Contributor
    Join Date
    12-05-2008
    Location
    Germany
    MS-Off Ver
    365
    Posts
    568

    Re: Macro to find, replace text and calculate VAT in a cell

    Hi Holger

    thank you ! so far so good, but a little mistake : the amount is only shown as the net amount ( netto betrag ) however, i need the tax amount, the difference between the brutto and net amount, e.g. on the first sheet: 59,93 Euro - 49,12 Euro = 10,81 Euro. So the cell should read: "Totale ordine: EUR 59,93 inc. EUR 10,81 VAT 22%"

  4. #4
    Forum Contributor
    Join Date
    12-05-2008
    Location
    Germany
    MS-Off Ver
    365
    Posts
    568

    Re: Macro to find, replace text and calculate VAT in a cell

    so the whole cell should read:

    Totale ordine: EUR 59,93 ( net. EUR 49,12 zzgl. EUR 10,81 VAT 22%)

  5. #5
    Forum Guru HaHoBe's Avatar
    Join Date
    02-19-2005
    Location
    Hamburg, Germany
    MS-Off Ver
    work: 2016 on Win10 (notebook), private: 2019 on Win10 (desktop), 2019 on Win11 (notebook)
    Posts
    8,197

    Re: Macro to find, replace text and calculate VAT in a cell

    Hi, Felix,

    just replace
    Please Login or Register  to view this content.
    with
    Please Login or Register  to view this content.
    Ciao,
    Holger

  6. #6
    Forum Contributor
    Join Date
    12-05-2008
    Location
    Germany
    MS-Off Ver
    365
    Posts
    568

    Re: Macro to find, replace text and calculate VAT in a cell

    oops, did you see my last post:

    the cell should read: "Totale ordine: EUR 59,93 (net. EUR 49,12 zzgl. EUR 10,81 VAT 22%)"

    blöde deutsche Steuergesetze der Nettobetrag muss auch ausgewiesen sein

  7. #7
    Forum Guru HaHoBe's Avatar
    Join Date
    02-19-2005
    Location
    Hamburg, Germany
    MS-Off Ver
    work: 2016 on Win10 (notebook), private: 2019 on Win10 (desktop), 2019 on Win11 (notebook)
    Posts
    8,197

    Re: Macro to find, replace text and calculate VAT in a cell

    Hi, Felix,

    instead of
    Please Login or Register  to view this content.
    Please Login or Register  to view this content.
    I wonder if Italians will know the meaning of zzgl.

    Ciao,
    Holger

  8. #8
    Forum Contributor
    Join Date
    12-05-2008
    Location
    Germany
    MS-Off Ver
    365
    Posts
    568

    Re: Macro to find, replace text and calculate VAT in a cell

    Hi Holger, great ! Works well except for a Runtime Error 91 - refering to the dblBase line ...

  9. #9
    Forum Guru HaHoBe's Avatar
    Join Date
    02-19-2005
    Location
    Hamburg, Germany
    MS-Off Ver
    work: 2016 on Win10 (notebook), private: 2019 on Win10 (desktop), 2019 on Win11 (notebook)
    Posts
    8,197

    Re: Macro to find, replace text and calculate VAT in a cell

    Hi, Felix,

    instead of
    Please Login or Register  to view this content.
    use
    Please Login or Register  to view this content.
    Ciao,
    Holger

  10. #10
    Forum Contributor
    Join Date
    12-05-2008
    Location
    Germany
    MS-Off Ver
    365
    Posts
    568

    Re: Macro to find, replace text and calculate VAT in a cell

    perfect !!! One last little thing before I can wish you a happy weekend. How can I align this specific cell to the right ? Because it gets sooo long and it exceeds the print area ?

  11. #11
    Forum Guru HaHoBe's Avatar
    Join Date
    02-19-2005
    Location
    Hamburg, Germany
    MS-Off Ver
    work: 2016 on Win10 (notebook), private: 2019 on Win10 (desktop), 2019 on Win11 (notebook)
    Posts
    8,197

    Re: Macro to find, replace text and calculate VAT in a cell

    Hi, Felix,

    you could use the macrp-recorder to get the basic code for this action.

    Add the code-line in blue:
    Please Login or Register  to view this content.
    Ciao,
    Holger

  12. #12
    Forum Contributor
    Join Date
    12-05-2008
    Location
    Germany
    MS-Off Ver
    365
    Posts
    568

    Re: Macro to find, replace text and calculate VAT in a cell

    Super ! Thank you so much Holger ! Bon weekend !

  13. #13
    Forum Contributor
    Join Date
    12-05-2008
    Location
    Germany
    MS-Off Ver
    365
    Posts
    568

    Re: Macro to find, replace text and calculate VAT in a cell

    sorry for having to reopen this. is there a way to automatically create a new sheet or workbook with all the net amounts added up ? E.g. new sheet A1:49,12 B1:49,12 / A2 49,12 B2: 98,24 and so on. So in Column B always the accumulated amount from each net amount in each invoice. I need this to check when I reach a certain amount.

    Edit:

    Probably best with a second macro
    Last edited by elgato74; 10-25-2014 at 03:47 PM.

  14. #14
    Forum Guru HaHoBe's Avatar
    Join Date
    02-19-2005
    Location
    Hamburg, Germany
    MS-Off Ver
    work: 2016 on Win10 (notebook), private: 2019 on Win10 (desktop), 2019 on Win11 (notebook)
    Posts
    8,197

    Re: Macro to find, replace text and calculate VAT in a cell

    Hi, Felix,

    you should take some time considering what you want prior to starting a thread and amending requests when the before last result is available - I loose my interest in this way of "Flickschusterei".

    Probably best with a second macro
    If a second macro it would be a new thread, and you would have to loop through the sheets again and do the same calculations but only in a longer string while in the original macro the data is available as dblBase.

    This macro will cut any available sting to the original length and start on it again., If you feel you want to keep the summaray sheet just alter the code to check the availability of the summary sheet and then decide whether to add a new one or delete the entries from A2 to the "C" & Rows.Count:
    Please Login or Register  to view this content.
    Ciao,
    Holger

  15. #15
    Forum Contributor
    Join Date
    12-05-2008
    Location
    Germany
    MS-Off Ver
    365
    Posts
    568

    Re: Macro to find, replace text and calculate VAT in a cell

    Hello Holger, yes you are certainly right. I apologize. That requirement came up after studying German tax laws

    However, the macro only adds up to sheet 35 then stops. Probably because sheet 36 does not have the "Totale ordine" text, as it is on the next sheet 37. Can this be fixed ?

    Felix

  16. #16
    Forum Guru HaHoBe's Avatar
    Join Date
    02-19-2005
    Location
    Hamburg, Germany
    MS-Off Ver
    work: 2016 on Win10 (notebook), private: 2019 on Win10 (desktop), 2019 on Win11 (notebook)
    Posts
    8,197

    Re: Macro to find, replace text and calculate VAT in a cell

    Hi, Felix,

    Please Login or Register  to view this content.
    Ciao,
    Holger

  17. #17
    Forum Contributor
    Join Date
    12-05-2008
    Location
    Germany
    MS-Off Ver
    365
    Posts
    568

    Re: Macro to find, replace text and calculate VAT in a cell

    Truly awesome Holger !

    Can you point out to me the code that only does the summary, should i decide that i want this to be a second macro to run after the first one.

  18. #18
    Forum Guru HaHoBe's Avatar
    Join Date
    02-19-2005
    Location
    Hamburg, Germany
    MS-Off Ver
    work: 2016 on Win10 (notebook), private: 2019 on Win10 (desktop), 2019 on Win11 (notebook)
    Posts
    8,197

    Re: Macro to find, replace text and calculate VAT in a cell

    Hi, Felix,

    the last If-Statement posted by me, only that you would have to make sure to know how the contents of the cell looks like and maybe use Mid and the start as the end of the first search string and the end to be two characters before the opening bracket.

    Ciao,
    Holger

+ 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. Creating a macro to find and replace text
    By Louise in forum Excel Formulas & Functions
    Replies: 17
    Last Post: 06-27-2014, 05:18 AM
  2. Replies: 3
    Last Post: 02-14-2014, 08:08 AM
  3. [SOLVED] Macro to copy cell contents then used Find & Replace to put text elswhere.
    By AimeeNZ in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 09-12-2012, 01:06 AM
  4. find in excel replace in word: find/replace text in text boxes and headers
    By dean.rogers in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 04-10-2012, 12:40 PM
  5. Creating a macro to find and replace text
    By Louise in forum Excel Formulas & Functions
    Replies: 0
    Last Post: 09-06-2005, 02:05 AM

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