+ Reply to Thread
Results 1 to 16 of 16

[SOLVED] Create button to save cell data to workbook header

Hybrid View

  1. #1
    Registered User
    Join Date
    08-20-2013
    Location
    Midlands, UK
    MS-Off Ver
    Excel 2007
    Posts
    30

    [SOLVED] Create button to save cell data to workbook header

    Hi,

    I am trying to create a button that when clicked will save the data from a cell into the center section of the header for all sheets in a workbook. The cell will contain a customer name and that is what I need in the header to be printed out with every sheet within a workbook.

    Any help would be appreciated.

    Thanks

    Tony
    Last edited by tailz; 08-28-2013 at 04:41 AM.

  2. #2
    Forum Expert
    Join Date
    06-12-2012
    Location
    Ridgefield Park, New Jersey
    MS-Off Ver
    Excel 2003,2007,2010
    Posts
    10,241

    Re: Create button to save cell data to workbook header

    Where will the cell be located. This assumes the cell is in Range("A1") Sheets("Sheet1")

    Private Sub Workbook_SheetActivate(ByVal Sh As Object)
    ActiveSheet.PageSetup.CenterHeader = Sheets("Sheet1").Range("A1").Value
    End Sub
    Or do you want something like this?

    Dim ws As Worksheet
    For Each ws In ActiveWorkbook.Worksheets
        ws.Activate
        ws.PageSetup.CenterHeader = Selection.Value
    Next ws
    End Sub
    Last edited by JOHN H. DAVIS; 08-27-2013 at 11:28 AM.

  3. #3
    Registered User
    Join Date
    08-20-2013
    Location
    Midlands, UK
    MS-Off Ver
    Excel 2007
    Posts
    30

    Re: Create button to save cell data to workbook header

    Hi John,

    I don't seem to be able to use either code within the

    Sub Button1_Click()
    End Sub
    Coding, any suggestions?

  4. #4
    Forum Expert
    Join Date
    06-12-2012
    Location
    Ridgefield Park, New Jersey
    MS-Off Ver
    Excel 2003,2007,2010
    Posts
    10,241

    Re: Create button to save cell data to workbook header

    The second suggestion worked for me?

    Private Sub CommandButton1_Click()
    For Each ws In ActiveWorkbook.Worksheets
        ws.Activate
        ws.PageSetup.CenterHeader = Selection.Value
    Next ws
    End Sub
    You have to make a selection before clicking.

  5. #5
    Registered User
    Join Date
    08-20-2013
    Location
    Midlands, UK
    MS-Off Ver
    Excel 2007
    Posts
    30

    Re: Create button to save cell data to workbook header

    Hi John,

    Still no joy, I created a new button and input the following,

    Private Sub CommandButton3_Click()
    For Each ws In ActiveWorkbook.Worksheets
        ws.Activate
        ws.PageSetup.CenterHeader = Selection.Value
    Next ws
    End Sub
    I made a cell selection and clicked on the Button3 but got the following error message,

    "Cannot run the macro "Machine Reportstest.xlsm'!Customer_Info_Button3_Click'. The macro may not be available in this workbook or all macros may be disabled."

    Macros are definitely enabled as my other buttons work ok.

    Any ideas?

    Cheers

    Tony

    Quote Originally Posted by JOHN H. DAVIS View Post
    The second suggestion worked for me?

    Private Sub CommandButton1_Click()
    For Each ws In ActiveWorkbook.Worksheets
        ws.Activate
        ws.PageSetup.CenterHeader = Selection.Value
    Next ws
    End Sub
    You have to make a selection before clicking.

  6. #6
    Forum Expert
    Join Date
    06-12-2012
    Location
    Ridgefield Park, New Jersey
    MS-Off Ver
    Excel 2003,2007,2010
    Posts
    10,241

    Re: Create button to save cell data to workbook header

    Can you attach a sample workbook? To attach a file, push the button with the paperclip (or scroll down to the Manage Attachments button), browse to the required file, and then push the Upload button.

  7. #7
    Registered User
    Join Date
    08-20-2013
    Location
    Midlands, UK
    MS-Off Ver
    Excel 2007
    Posts
    30

    Re: Create button to save cell data to workbook header

    Quote Originally Posted by JOHN H. DAVIS View Post
    Can you attach a sample workbook? To attach a file, push the button with the paperclip (or scroll down to the Manage Attachments button), browse to the required file, and then push the Upload button.
    Hi John,

    Workbook attached, I have removed the button, which I had placed alongside the entry cell for the customer name and also the vba module.

    Cheers

    Tony
    Attached Files Attached Files

  8. #8
    Registered User
    Join Date
    08-20-2013
    Location
    Midlands, UK
    MS-Off Ver
    Excel 2007
    Posts
    30

    Re: Create button to save cell data to workbook header

    Hi John,

    I have no idea what is going on, still the same message as before, all other buttons work fine. Very odd.

  9. #9
    Forum Expert
    Join Date
    06-12-2012
    Location
    Ridgefield Park, New Jersey
    MS-Off Ver
    Excel 2003,2007,2010
    Posts
    10,241

    Re: Create button to save cell data to workbook header

    I tested it on the file you attached? It worked fine. Maybe someone else may have some ideas?

  10. #10
    Registered User
    Join Date
    08-20-2013
    Location
    Midlands, UK
    MS-Off Ver
    Excel 2007
    Posts
    30

    Re: Create button to save cell data to workbook header

    Hi John,

    I have attached the workbook again, this time with button and code, can you see if it works on your system please?

    Regards

    Tony
    Attached Files Attached Files

  11. #11
    Registered User
    Join Date
    08-20-2013
    Location
    Midlands, UK
    MS-Off Ver
    Excel 2007
    Posts
    30

    Re: Create button to save cell data to workbook header

    I sorted out the error as being previousaly experienced however I am now getting a mismatch error on

    x = Selection.Value
    I am using a text string in the cell,

    dim x As String
    should be correct, so any ideas why the "Runtime error 13, type mismatch"?

  12. #12
    Registered User
    Join Date
    08-20-2013
    Location
    Midlands, UK
    MS-Off Ver
    Excel 2007
    Posts
    30

    Re: Create button to save cell data to workbook header

    Hi,

    Is anyone able to offer any help with this issue? I am struggling to get a button to do this task. I am open to alternate methods of adding this cell data into the workbook.

    Many thanks

    Tony
    Last edited by tailz; 08-28-2013 at 04:02 AM.

  13. #13
    Forum Expert
    Join Date
    06-12-2012
    Location
    Ridgefield Park, New Jersey
    MS-Off Ver
    Excel 2003,2007,2010
    Posts
    10,241

    Re: Create button to save cell data to workbook header

    Machine Reportstest.xlsm

    Tony:

    I added a command button to Column Q. If you select a cell and click it you'll see that it addeds a Center Header based on the selection to all worksheets. Isn't that what you're trying to achieve?

  14. #14
    Registered User
    Join Date
    08-20-2013
    Location
    Midlands, UK
    MS-Off Ver
    Excel 2007
    Posts
    30

    Re: [SOLVED] Create button to save cell data to workbook header

    Hi John,

    Yes I eventually figured out where I was going wrong, so it is all sorted now. Many thanks

  15. #15
    Forum Expert
    Join Date
    06-12-2012
    Location
    Ridgefield Park, New Jersey
    MS-Off Ver
    Excel 2003,2007,2010
    Posts
    10,241

    Re: [SOLVED] Create button to save cell data to workbook header

    Took us awhile, but we got there. Glad to hear you've got a working solution.

+ 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. create and save new workbook from template, using cell data and VBA
    By jimoneill64 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 05-15-2013, 05:30 AM
  2. [SOLVED] Re: How To Create a macro for Cell References into Header for a workbook
    By k_vivek27 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 01-23-2013, 02:24 PM
  3. How To Create a macro for Cell References into Header for a workbook
    By k_vivek27 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 01-19-2013, 04:51 AM
  4. A button to save workbook with file name from K1 cell
    By danield_sk in forum Excel - New Users/Basics
    Replies: 5
    Last Post: 11-13-2007, 11:33 PM
  5. [SOLVED] Create a button to Save As the workbook
    By Helen in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 11-24-2005, 02:25 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