+ Reply to Thread
Results 1 to 14 of 14

Macro to change cell value

  1. #1
    Registered User
    Join Date
    02-01-2013
    Location
    Plymouth, England
    MS-Off Ver
    Excel 2010
    Posts
    7

    Question Macro to change cell value

    Hi.... and help!
    I'm a newbie to the forum and a newbie to VB but picking it up fairly quickly (the simple stuff, at least). I'm having to write some formatting macros at work and am so far doing ok but there's just one step I just can't seem to get as it involves conditionally changing a cell value and then the cell alignment. I've tried various IF functions but have concluded that the only way to do this must be through the macro... here goes....

    I'm using Excel Report Generator to extract data from my database into the Excel template I'm creating the macro for. The sheet that I'm having issues with is because sometimes there will be no data for the period. What my boss wants me to do is set up the macro to include a step where it looks to see if the top row is blank and, if it is, to merge the row (I'm trying to sell 'Center Across Selection' to her) and type 'None' so that the client receiving the report doesn't go looking for data that doesn't exist. Merging has been a nightmare so I've settled for conditionally formatting borders and the whole =IF(..., then "NONE") has left me with a bruise on my forehead from banging it against my desk. Help??


    Thanks so much!
    Attached Files Attached Files
    Last edited by rosellie; 02-21-2013 at 09:48 AM. Reason: changing attachment

  2. #2
    Forum Expert
    Join Date
    03-28-2012
    Location
    TBA
    MS-Off Ver
    Office 365
    Posts
    12,454

    Re: Macro to change cell value

    A picture is not helpful to test a code. Please attach a sample book. Advance- attachment

  3. #3
    Registered User
    Join Date
    02-01-2013
    Location
    Plymouth, England
    MS-Off Ver
    Excel 2010
    Posts
    7

    Re: Macro to change cell value

    Sorry - hopefully I've attached the right thing this time? I did warn you I'm a newbie!

  4. #4
    Forum Expert
    Join Date
    03-28-2012
    Location
    TBA
    MS-Off Ver
    Office 365
    Posts
    12,454

    Re: Macro to change cell value

    Rose,
    Okay! Which rows/columns you wish to merge and what is the criteria/condition for the merge?

  5. #5
    Registered User
    Join Date
    02-01-2013
    Location
    Plymouth, England
    MS-Off Ver
    Excel 2010
    Posts
    7

    Re: Macro to change cell value

    I need to merge the top row of data (A2:H2) if the whole row is blank.

  6. #6
    Forum Expert
    Join Date
    03-28-2012
    Location
    TBA
    MS-Off Ver
    Office 365
    Posts
    12,454

    Re: Macro to change cell value

    So, if a whole row in a-h is blank, you want to merge the whole row. If any cell with in A-H si not blank, you do not want to merge that cell. Am I right?

  7. #7
    Registered User
    Join Date
    02-01-2013
    Location
    Plymouth, England
    MS-Off Ver
    Excel 2010
    Posts
    7

    Re: Macro to change cell value

    Yes, it must be the whole row.

  8. #8
    Forum Expert
    Join Date
    03-28-2012
    Location
    TBA
    MS-Off Ver
    Office 365
    Posts
    12,454

    Re: Macro to change cell value

    Try this one on the attached

    Please Login or Register  to view this content.
    Last edited by AB33; 02-21-2013 at 11:39 AM.

  9. #9
    Registered User
    Join Date
    02-01-2013
    Location
    Plymouth, England
    MS-Off Ver
    Excel 2010
    Posts
    7

    Re: Macro to change cell value

    That works great... but I should have been clearer when I said the whole row of data, I meant the range A2:H2. This is the range I want to merge. Sorry, for confusing matters by saying row... I feel like I'm learning a new language... which I guess I am! No wonder you had to double check - why would anyone in their right mind merge a whole row of a spreadsheet?!

    Also, once the cell has merged, I want it show show a text value: NONE. Is that straightforward?

  10. #10
    Forum Expert
    Join Date
    03-28-2012
    Location
    TBA
    MS-Off Ver
    Office 365
    Posts
    12,454

    Re: Macro to change cell value

    "why would anyone in their right mind merge a whole row of a spreadsheet?

    To give lots of pain and headache for people who want to write a code on merge cells.

    I am, like you, is also learnning VBA on this forum. Some people on this forum will not even touch a sample book which has merged cells on it. VBA and merged cells do not see eye to eye.
    I have amended the above code as per requested, but I am not sure what you mean by "Text NONE". It is probably an issue of formatting. Could you please explain?

  11. #11
    Registered User
    Join Date
    02-01-2013
    Location
    Plymouth, England
    MS-Off Ver
    Excel 2010
    Posts
    7

    Re: Macro to change cell value

    You are wonderful! That code is perfect! Thank you

    The whole thing with 'NONE' is that I want the new merged cell to contain the word 'NONE'. I live without it if that's too much hassle...

  12. #12
    Forum Expert
    Join Date
    03-28-2012
    Location
    TBA
    MS-Off Ver
    Office 365
    Posts
    12,454

    Re: Macro to change cell value

    Rose,
    Amended again. Please above

  13. #13
    Registered User
    Join Date
    02-01-2013
    Location
    Plymouth, England
    MS-Off Ver
    Excel 2010
    Posts
    7

    Re: Macro to change cell value

    Perfect! You have officially made my day! Thanks so much

  14. #14
    Forum Expert
    Join Date
    03-28-2012
    Location
    TBA
    MS-Off Ver
    Office 365
    Posts
    12,454

    Re: Macro to change cell value

    Rose,
    You are welcome!
    Glad to be helpful!
    Could you please now close this thread as solved. Go in to the top right-hand side of this page, choose, "Thread Tools", you then select, solved from the drop down menu?

+ 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