+ Reply to Thread
Results 1 to 14 of 14

Problem in customizing ribbon

Hybrid View

  1. #1
    Valued Forum Contributor ImranBhatti's Avatar
    Join Date
    03-27-2014
    Location
    Rawalpindi,Pakistan
    MS-Off Ver
    Office 365
    Posts
    1,785

    Problem in customizing ribbon

    Hello

    I have a commandbutton on my sheet11.I have have created an icon on my custom ribbon and want the code of that commandbutton run if i click on the icon on my new ribbon tab. How can I?

    Best Regards
    Imran Bhatti
    Teach me Excel VBA

  2. #2
    Valued Forum Contributor PFDave's Avatar
    Join Date
    05-17-2012
    Location
    Milton Keynes, England
    MS-Off Ver
    Excel 2013
    Posts
    1,067

    Re: Problem in customizing ribbon

    In customize ribbon, top left dropdown defaults to Popular Commands, change to macros then select the required macro from there

  3. #3
    Valued Forum Contributor ImranBhatti's Avatar
    Join Date
    03-27-2014
    Location
    Rawalpindi,Pakistan
    MS-Off Ver
    Office 365
    Posts
    1,785

    Re: Problem in customizing ribbon

    the code resides in the click event of the commandbutton1 and this button is placed on sheet.

    Like
    Private sub CommandButton1_Click()
    Code here
    End sub
    YOur mentioned dropdown shows only macros which are in a modual and not the click events of forms controls

  4. #4
    Valued Forum Contributor PFDave's Avatar
    Join Date
    05-17-2012
    Location
    Milton Keynes, England
    MS-Off Ver
    Excel 2013
    Posts
    1,067

    Re: Problem in customizing ribbon

    So does your code require the user to complete something and then click the command button e.g show a userform first? Or can you just duplicate the code into module and select the macro from there?

  5. #5
    Valued Forum Contributor ImranBhatti's Avatar
    Join Date
    03-27-2014
    Location
    Rawalpindi,Pakistan
    MS-Off Ver
    Office 365
    Posts
    1,785

    Re: Problem in customizing ribbon

    by creating a duplicate an error occurs
    " Object Required"

    and this line of code gets highlighted
    If Cells(i, 5) = legname And Cells(i, 1) >= DTPicker1.Value And Cells(i, 1) <= DTPicker2.Value Then

  6. #6
    Valued Forum Contributor ImranBhatti's Avatar
    Join Date
    03-27-2014
    Location
    Rawalpindi,Pakistan
    MS-Off Ver
    Office 365
    Posts
    1,785

    Re: Problem in customizing ribbon

    Lemme do it

  7. #7
    Valued Forum Contributor PFDave's Avatar
    Join Date
    05-17-2012
    Location
    Milton Keynes, England
    MS-Off Ver
    Excel 2013
    Posts
    1,067

    Re: Problem in customizing ribbon

    So you need to assign a macro to show your form which contains DTPicker.

  8. #8
    Valued Forum Contributor ImranBhatti's Avatar
    Join Date
    03-27-2014
    Location
    Rawalpindi,Pakistan
    MS-Off Ver
    Office 365
    Posts
    1,785

    Re: Problem in customizing ribbon

    Sorry for providing less information. Here are the complete info

    the code in the click event of commandbutton1 (which is on sheet and not in a userform) and this code goes to a journal determines the rows whether the column of the journal contains the dates equal to or in between the dates of dtpicker1 and dtpicker2 then it determines wheter the column 5 of journal contains a account head that is in L2 cell after determining these 3 criterias this code copies all the rows(meeting criteria) from the journal and pastes to another location as a ledger.
    I want to keep both this command button and a button on the ribbon .Both should perform the above mentioned task.

    Hope now it is all conveyed

    Best Regards
    Imran Bhatti

  9. #9
    Forum Guru xlnitwit's Avatar
    Join Date
    06-27-2016
    Location
    London
    MS-Off Ver
    Windows: 2010; Mac: 16.13 (O365)
    Posts
    7,085

    Re: Problem in customizing ribbon

    You will need to post the code for the click event, I feel.

    Alternatively, you might create a macro in a normal module thus
    Sub DoButtonClick()
    Application.Run "Sheet1.CommandButton1_Click"
    End Sub
    and assign this macro to your ribbon button. Sheet1 needs to be replaced with the code name- not the tab name- of the sheet with the button.
    Don
    Please remember to mark your thread 'Solved' when appropriate.

  10. #10
    Valued Forum Contributor ImranBhatti's Avatar
    Join Date
    03-27-2014
    Location
    Rawalpindi,Pakistan
    MS-Off Ver
    Office 365
    Posts
    1,785

    Re: Problem in customizing ribbon

    Here is the code
    Private Sub CommandButton1_Click()
    Application.ScreenUpdating = False
        Application.DisplayAlerts = False
        Application.EnableEvents = False
        Sheets("Journal").Activate
        Range("L10").Value = "Opening Balance"
        Range("R10").Formula = "=SUMIFS(G8:G1048576,E8:E1048576,N3,A8:A1048576,""<""&M1) + VLOOKUP(N3,Chart_of_Accounts!P3:T314,3,0)"
        Range("S10").Formula = "=SUMIFS(H8:H1048576,E8:E1048576,N3,A8:A1048576,""<""&M1)+VLOOKUP(N3,Chart_of_Accounts!P3:T314,4,0)"
        Range("T10").Formula = "=R10" & "-" & "S10"
        Range("L9").Value = "Voucher Date"
        Range("M9").Value = "Voucher #"
        Range("N9").Value = "Cheque #"
        Range("O9").Value = "Main Acc"
        Range("P9").Value = "Sub-Acc"
        Range("Q9").Value = "Description"
        Range("R9").Value = "Debit"
        Range("S9").Value = "Credit"
        Range("T9").Value = "Balance"
        Call LedgerHeading
        Dim acc As String
        Dim jawab As String
        acc = Mid(Sheets("Journal").Range("L2").Value, 7, 100)
        jawab = "Ledger:" & " " & acc
        Range("L7").Value = jawab
    
        Dim legname As String
        Dim lastrow As Double
        Dim i As Double
        Dim sDate As Date
        Dim lDate As Date
        Application.ScreenUpdating = False
        Sheets("Journal").Range("L11:t1048576").Clear
        Sheets("Journal").Range("L11:t1048576").Borders.LineStyle = xlNone
        legname = Sheets("Journal").Range("L2").Value
        lastrow = Sheets("Journal").Range("a1048576").End(xlUp).Row
    
        For i = 1 To lastrow
            If Cells(i, 5) = legname And Cells(i, 1) >= DTPicker1.Value And Cells(i, 1) <= DTPicker2.Value Then
    
                Range(Cells(i, 1), Cells(i, 8)).Copy
                Range("L1048576").End(xlUp).Offset(1, 0).PasteSpecial xlPasteFormulasAndNumberFormats
            End If
        Next i
    
        Range("L1048576").End(xlUp).Offset(1, 0).Select
        Selection.Resize(, 9).Select
        With Selection.Borders(xlEdgeTop)
            .LineStyle = xlContinuous
            .ColorIndex = xlAutomatic
            .TintAndShade = 0
            .Weight = xlThin
        End With
        With Selection.Borders(xlEdgeBottom)
            .LineStyle = xlDouble
            .ColorIndex = xlAutomatic
            .TintAndShade = 0
            .Weight = xlThick
        End With
        Selection.Borders(xlEdgeRight).LineStyle = xlNone
        Selection.Borders(xlInsideVertical).LineStyle = xlNone
        Selection.Borders(xlInsideHorizontal).LineStyle = xlNone
        With Selection.Font
            .Name = "Arial Black"
            .Bold = True
            .Size = 11
            .Color = vbBlue
        End With
        Range("Q7").Value = "From  " & DTPicker1.Value & "  to   " & DTPicker2.Value
        Dim Lrow As Long
        Lrow = Range("L1048576").End(xlUp).Offset(1, 0).Row - 1
        Range("L1048576").End(xlUp).Offset(1, 0).Select
        ActiveCell.Offset(, 6).Formula = "=sum(R10:" & "R" & Lrow & ")"
        ActiveCell.Offset(, 7).Formula = "=sum(S10:" & "S" & Lrow & ")"
        ActiveCell.Offset(, 7).NumberFormat = Range("S10").NumberFormat
        ActiveCell.Value = "TOTAL"
    
        Dim irow As Long
        Application.ScreenUpdating = False
        Application.EnableEvents = False
        irow = Range("L1048576").End(xlUp).Row
        Range("T11:T" & irow).Formula = "=T10" & "+" & "R11" & "-" & "S11"
        Range("T" & irow).Formula = "= R" & irow & "-" & "s" & irow
        Range("T11:T" & irow).NumberFormat = Range("T10").NumberFormat
        Range("L7:T" & irow).Copy
        Range("L7:T" & irow).PasteSpecial xlPasteValues
        With Range("L11:M" & irow).Select
            Selection.HorizontalAlignment = xlLeft
        End With
        With Range("R9:T" & irow).Select
            Selection.HorizontalAlignment = xlLeft
        End With
        Dim brow As Long
        brow = Sheets("journal").Range("L1048576").End(xlUp).Offset(-1, 0).Row
        With Range("L11:T" & brow).Borders(xlInsideHorizontal)
            .LineStyle = xlContinuous
            .ColorIndex = xlAutomatic
            .TintAndShade = 0
            .Weight = xlHairline
        End With
        Range("L11").Select
    
        Application.CutCopyMode = False
        Application.ScreenUpdating = True
        Application.EnableEvents = True
        Application.DisplayAlerts = True
    End Sub

  11. #11
    Forum Guru xlnitwit's Avatar
    Join Date
    06-27-2016
    Location
    London
    MS-Off Ver
    Windows: 2010; Mac: 16.13 (O365)
    Posts
    7,085

    Re: Problem in customizing ribbon

    Which sheet is that code in?

  12. #12
    Valued Forum Contributor ImranBhatti's Avatar
    Join Date
    03-27-2014
    Location
    Rawalpindi,Pakistan
    MS-Off Ver
    Office 365
    Posts
    1,785

    Re: Problem in customizing ribbon

    commandbutton is placed in sheet11 . the journal and ledger are also on the same sheets

  13. #13
    Forum Guru xlnitwit's Avatar
    Join Date
    06-27-2016
    Location
    London
    MS-Off Ver
    Windows: 2010; Mac: 16.13 (O365)
    Posts
    7,085

    Re: Problem in customizing ribbon

    Try this code in a normal module and call this routine from the button click and your menu item
    Sub updateJournal()
        With Application
            .ScreenUpdating = False
            .DisplayAlerts = False
            .EnableEvents = False
        End With
        With Sheets("Journal")
            .Range("L10").Value = "Opening Balance"
            .Range("R10").Formula = "=SUMIFS(G8:G1048576,E8:E1048576,N3,A8:A1048576,""<""&M1) + VLOOKUP(N3,Chart_of_Accounts!P3:T314,3,0)"
            .Range("S10").Formula = "=SUMIFS(H8:H1048576,E8:E1048576,N3,A8:A1048576,""<""&M1)+VLOOKUP(N3,Chart_of_Accounts!P3:T314,4,0)"
            .Range("T10").Formula = "=R10" & "-" & "S10"
            .Range("L9:T9").Value = Array("Voucher Date", "Voucher #", "Cheque #", "Main Acc", _
                                          "Sub-Acc", "Description", "Debit", "Credit", "Balance")
            .Activate
            Call LedgerHeading
            Dim acc               As String
            Dim jawab             As String
            acc = Mid(.Range("L2").Value, 7, 100)
            jawab = "Ledger:" & " " & acc
            .Range("L7").Value = jawab
    
            Dim legname           As String
            Dim lastrow           As Double
            Dim i                 As Double
            Dim sDate             As Date
            Dim lDate             As Date
            Application.ScreenUpdating = False
            .Range("L11:t1048576").Clear
            .Range("L11:t1048576").Borders.LineStyle = xlNone
            legname = .Range("L2").Value
            lastrow = .Range("a1048576").End(xlUp).Row
    
            For i = 1 To lastrow
                If .Cells(i, 5) = legname And .Cells(i, 1) >= .DTPicker1.Value And .Cells(i, 1) <= .DTPicker2.Value Then
    
                    .Range(.Cells(i, 1), .Cells(i, 8)).Copy
                    .Range("L1048576").End(xlUp).Offset(1, 0).PasteSpecial xlPasteFormulasAndNumberFormats
                End If
            Next i
    
            With .Range("L1048576").End(xlUp).Offset(1, 0).Resize(, 9)
                With .Borders(xlEdgeTop)
                    .LineStyle = xlContinuous
                    .ColorIndex = xlAutomatic
                    .TintAndShade = 0
                    .Weight = xlThin
                End With
                With .Borders(xlEdgeBottom)
                    .LineStyle = xlDouble
                    .ColorIndex = xlAutomatic
                    .TintAndShade = 0
                    .Weight = xlThick
                End With
                .Borders(xlEdgeRight).LineStyle = xlNone
                .Borders(xlInsideVertical).LineStyle = xlNone
                .Borders(xlInsideHorizontal).LineStyle = xlNone
                With .Font
                    .Name = "Arial Black"
                    .Bold = True
                    .Size = 11
                    .Color = vbBlue
                End With
            End With
            .Range("Q7").Value = "From  " & .DTPicker1.Value & "  to   " & .DTPicker2.Value
            Dim Lrow              As Long
            Lrow = .Range("L1048576").End(xlUp).Offset(1, 0).Row - 1
            With .Range("L1048576").End(xlUp).Offset(1, 0)
                .Offset(, 6).Formula = "=sum(R10:" & "R" & Lrow & ")"
                .Offset(, 7).Formula = "=sum(S10:" & "S" & Lrow & ")"
                .Offset(, 7).NumberFormat = Range("S10").NumberFormat
                .Value = "TOTAL"
            End With
    
            Dim irow              As Long
            irow = .Range("L1048576").End(xlUp).Row
            .Range("T11:T" & irow).Formula = "=T10" & "+" & "R11" & "-" & "S11"
            .Range("T" & irow).Formula = "= R" & irow & "-" & "s" & irow
            .Range("T11:T" & irow).NumberFormat = .Range("T10").NumberFormat
            .Range("L7:T" & irow).Copy
            .Range("L7:T" & irow).PasteSpecial xlPasteValues
            .Range("L11:M" & irow).HorizontalAlignment = xlLeft
            .Range("R9:T" & irow).HorizontalAlignment = xlLeft
            Dim brow              As Long
            brow = .Range("L1048576").End(xlUp).Offset(-1, 0).Row
            With .Range("L11:T" & brow).Borders(xlInsideHorizontal)
                .LineStyle = xlContinuous
                .ColorIndex = xlAutomatic
                .TintAndShade = 0
                .Weight = xlHairline
            End With
        End With
        With Application
            .CutCopyMode = False
            .ScreenUpdating = True
            .EnableEvents = True
            .DisplayAlerts = True
        End With
    End Sub

  14. #14
    Valued Forum Contributor ImranBhatti's Avatar
    Join Date
    03-27-2014
    Location
    Rawalpindi,Pakistan
    MS-Off Ver
    Office 365
    Posts
    1,785

    Re: Problem in customizing ribbon

    Hi xlnitwit it worked perfectly.but I found another problem with custom ribbon. But I am gona mark this thread and please and post a new thread for the next problem in line with this problem."After changing the location of the file or renaming it the Custom ribbon buttons don't work at all".

+ 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. Customizing the ribbon in 2010(vs 2007)
    By Bishonen in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 04-15-2013, 03:29 AM
  2. Customizing a ribbon with macros
    By DrNerj in forum Excel General
    Replies: 0
    Last Post: 08-15-2012, 10:15 AM
  3. Customizing ribbon with buttons for macros
    By DrNerj in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 08-15-2012, 09:28 AM
  4. [SOLVED] Customizing Ribbon in Word 2010
    By kapucino in forum Word Formatting & General
    Replies: 4
    Last Post: 05-15-2012, 07:54 AM
  5. Customizing Ribbon Keytips
    By a2olmo in forum Excel General
    Replies: 4
    Last Post: 05-06-2010, 09:58 PM
  6. Excel 2007 : Customizing the ribbon/menu items.
    By LAF in forum Excel General
    Replies: 2
    Last Post: 07-29-2008, 12:37 PM
  7. Replies: 1
    Last Post: 06-11-2008, 11:23 PM

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