+ Reply to Thread
Results 1 to 4 of 4

adding cell format in created VBA function

  1. #1
    Registered User
    Join Date
    12-03-2013
    Location
    Mestreech, Limburg
    MS-Off Ver
    Excel 2003
    Posts
    4

    Question adding cell format in created VBA function

    I Have created a Function in VBA so that I can make barcodes in excel.
    The font that is required to display the barcode is 'Code 128'.

    Now I manual select the font but is it possible to enclose this in my VBA function?
    I'm using Excel 03
    Using Excel 2003

  2. #2
    Forum Expert
    Join Date
    08-02-2013
    Location
    Québec
    MS-Off Ver
    Excel 2003, 2007, 2013
    Posts
    1,412

    Re: adding cell format in created VBA function

    Hi and welcome to the forum,

    This will change the activecell font. Change it to your needs :

    Please Login or Register  to view this content.
    If it doesn't work, please share your code.
    GC Excel

    If this post helps, then click the star icon (*) in the bottom left-hand corner of my post to Add reputation.

  3. #3
    Registered User
    Join Date
    12-03-2013
    Location
    Mestreech, Limburg
    MS-Off Ver
    Excel 2003
    Posts
    4

    Re: adding cell format in created VBA function

    Thanx for your quick response but it's not a Sub but a Function in VBA

    I already tried that line and several other methods but the Function ignores then or I get '#value' as answer

    VBA_module:
    Function BarCode(ArtNr As String)
    ...
    BarCode = "Ì" & ArtNr & ControlSign & "Î"
    End Function

    ArtNr is referring to a cell that contains a 5 or 6 digit number.
    ... contains all actions to define the ControlSign

    The function BarCode calculates the ControlSign which is needed so that the system knows if it's legit.
    as output you get the last line of the Function

    eg.
    Cell A1 contains a number (014063)
    Cell B1 contains the formula: =BarCode(A1)
    Cell B1 displays:"Ì014063¢Î"

    When the Font is 'Code 128' you will have the barcode

  4. #4
    Forum Guru
    Join Date
    04-13-2005
    Location
    North America
    MS-Off Ver
    2002/XP and 2007
    Posts
    16,079

    Re: adding cell format in created VBA function

    UDF's are not allowed to modify the spreadsheet environment -- such as changing the format of a cell. The UDF can return the text string, but it cannot specify the font for that text string. You will either have to continue manually formatting the output cell, or put the code to format the cell into a SUB() procedure.
    Quote Originally Posted by shg
    Mathematics is the native language of the natural world. Just trying to become literate.

+ 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. [SOLVED] Adding numbers within an already created value
    By BLK in forum Excel General
    Replies: 2
    Last Post: 08-16-2006, 02:55 PM
  2. Adding a date when something was created.
    By Aikisteve in forum Excel Formulas & Functions
    Replies: 6
    Last Post: 08-11-2006, 06:08 AM
  3. [SOLVED] How do I save a custom cell format that I created?
    By mrs_teeks in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 05-07-2006, 11:00 PM
  4. [SOLVED] Adding in another conditional format on the same cell
    By Kelly Lim in forum Excel General
    Replies: 4
    Last Post: 05-23-2005, 05:06 AM
  5. Adding functionality to created Buttons
    By bhofsetz in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 04-13-2005, 07:03 PM

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