excel - How to combine two vba codes? -


i'd combine (run) 2 different vba functions in 1 sheet. how that?

option explicit private sub worksheet_beforedoubleclick(byval target range, cancel boolean) 'updateby extendoffice 20161123     dim rgtable range     dim rgdata range     dim xcolumn integer     on error resume next     application.screenupdating = false     set rgtable = range("mydata")     rgtable         set rgdata = .offset(1, 0).resize(.rows.count - 1, .columns.count)         if not application.intersect(activecell, rgdata.cells) nothing             xcolumn = activecell.column - .column + 1             if activesheet.autofiltermode = false                 .autofilter             end if             if activesheet.autofilter.filters(xcolumn).on = true                 .autofilter field:=xcolumn             else                 .autofilter field:=xcolumn, criteria1:=activecell.value             end if         end if     end     set rgdata = nothing     set rgtable = nothing     application.screenupdating = true end sub 

and

public blntoggle boolean private sub worksheet_beforedoubleclick _     (byval target range, cancel boolean) 'updateby extendoffice 20161123     dim lastcolumn long, keycolumn long, lastrow long     dim sortrange range     lastcolumn = _     cells.find(what:="*", after:=range("a1"), _     searchorder:=xlbycolumns, searchdirection:=xlprevious).column     keycolumn = target.column     if keycolumn > lastcolumn exit sub     application.screenupdating = false     cancel = true     lastrow = cells(rows.count, keycolumn).end(xlup).row     set sortrange = target.currentregion     blntoggle = not blntoggle     if blntoggle = true         sortrange.sort _         key1:=cells(2, keycolumn), order1:=xlascending, header:=xlyes     else         sortrange.sort _         key1:=cells(2, keycolumn), order1:=xldescending, header:=xlyes     end if     set sortrange = nothing     application.screenupdating = true end sub 

source: https://www.extendoffice.com/documents/excel/4258-excel-click-cell-to-filter.html https://www.extendoffice.com/documents/excel/4259-excel-click-on-header-to-sort.html

this how take 2 functionalities one. imagine have code1 , code2 , want build code1andcode2together:

public sub code1()     debug.print "i code 1" end sub  public sub code2()     debug.print "i code 2" end sub 

what should check these codes doing , unite them together. in general, should this:

public sub code1andcode2together()     debug.print "i code 1"     debug.print "i code 2" end sub 

or this:

public sub code1andcode2together()     code1     code2 end sub 

in case - copy , paste not work, start. try understand codes doing , try achieve it.


Comments

Popular posts from this blog

php - Vagrant up error - Uncaught Reflection Exception: Class DOMDocument does not exist -

vue.js - Create hooks for automated testing -

Add new key value to json node in java -