+ Reply to Thread
Results 1 to 7 of 7

VBA to change font formatting

  1. #1
    Forum Contributor
    Join Date
    02-20-2014
    Location
    Ireland
    MS-Off Ver
    Excel 2013
    Posts
    108

    VBA to change font formatting

    Hi All,

    I have written a code that mainly copy's and paste's data between workbooks. This all works fine until I tried to format the font in a particular cell with code. I just cant seem to get my head around whats causing the problem as I use the same snippet of code twice in the same module. the first time it encounters the snippet of code to format the font it fails, but if i delete it and only leave in the second bit of format code it works fine. Hard to explain so I have posted my full code below and highlighted in red where the code runs into an error

    Please Login or Register  to view this content.
    The error i receive is "Run-time error '1004': Unable to set the Name property of the font class"

    If I remove the name property it simply fails on the next line of code. If I remove the whole section the code runs including the identical code just below the offending bit of code.

    I am new enough to VBA so maybe it is something simple i have overlooked. Or even any advice on how i could clean up this code would be appreciated.

    Thanks in advance

    Simon

  2. #2
    Valued Forum Contributor
    Join Date
    09-21-2011
    Location
    Birmingham UK
    MS-Off Ver
    Excel 2003/7/10
    Posts
    2,188

    Re: VBA to change font formatting

    I think its cause you dont have anything selected, you've just pasted. Try setting the range

    so
    Please Login or Register  to view this content.


    where rows count will need to be the count of the rows copied. You are using it, so just put it in a var.
    Hope this helps

    Sometimes its best to start at the beginning and learn VBA & Excel.

    Please dont ask me to do your work for you, I learnt from Reading books, Recording, F1 and Google and like having all of this knowledge in my head for the next time i wish to do it, or wish to tweak it.
    Available for remote consultancy work PM me

  3. #3
    Forum Contributor
    Join Date
    02-20-2014
    Location
    Ireland
    MS-Off Ver
    Excel 2013
    Posts
    108

    Re: VBA to change font formatting

    I understand what you are saying, makes sense to me, but it still not working. As you can see below the highlighted RED code, the code just copies and pastes the same information to another sheet. If I delete the whole first bit (highlighted red) and run the code it works fine. formatting the text and all.

    Please Login or Register  to view this content.
    The more time i spend looking at it the more stumped I get, I have extracted the code and modified it to run just the formatting on a completely separate workbook and it works fine.

    Also rows.count wont be necessary as it will always be "F5" that i want to format

  4. #4
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: VBA to change font formatting

    Does this work?
    Please Login or Register  to view this content.
    If posting code please use code tags, see here.

  5. #5
    Forum Contributor
    Join Date
    02-20-2014
    Location
    Ireland
    MS-Off Ver
    Excel 2013
    Posts
    108

    Re: VBA to change font formatting

    Thanks for taking the time to reply, unfortunately when I insert your bit of code it still returns the same error as I mentioned in the first post :-S

  6. #6
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: VBA to change font formatting

    Can you upload an example workbook?

    Click on GO ADVANCED and use the paperclip icon to open the upload window.

  7. #7
    Forum Contributor
    Join Date
    02-20-2014
    Location
    Ireland
    MS-Off Ver
    Excel 2013
    Posts
    108

    Re: VBA to change font formatting

    I was preparing some workbooks to upload as they hold a lot of sensitive information. I had to delete some sheets and macros that wouldn't be necessary for an example. Then I had my example workbook ready to upload, so I said I will run the code again. And lone behold it ran perfect no issues. I didn't make this document and am only modifying it so had overlooked any clashes of code, which seems to be the case. But only thanks to you asking for an example workbook I came across the issue. That deserves some rep!

    Thanks all for your replies

    Simon

+ 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] Conditional Formatting - change font color in B25 if a separate box B23 says N/A
    By H57 in forum Excel Formulas & Functions
    Replies: 5
    Last Post: 10-24-2013, 04:49 AM
  2. 'Conditional Formatting' CODE to change Font Size
    By trickyricky in forum Excel General
    Replies: 5
    Last Post: 03-26-2011, 12:58 PM
  3. [SOLVED] Change font type in Conditional Formatting
    By Kyndsberg in forum Excel General
    Replies: 1
    Last Post: 01-23-2006, 05:20 PM
  4. Replies: 5
    Last Post: 04-04-2005, 05:06 PM
  5. Replies: 1
    Last Post: 01-06-2005, 07:06 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