View Single Post
  #1   Report Post  
Posted to microsoft.public.excel.programming
DogLover DogLover is offline
external usenet poster
 
Posts: 37
Default Call Subroutine in Excel

Please help. I am trying to set up a subroutine that I can call several
times to eliminate having to type this code a bunch of times. The
subroutine that I would like to call is this Newtest. The subroutines where
it is used and Newtest are actually all in the same workbook.

Public Sub Newtest_Click()
Dim NewFillRange, lookuprng As Range
Dim EntityVar, NewRange As String
Dim StartRow, EndRow As Integer

If CheckBoxEntity.Value = False Then Set NewFillRange =
Worksheets("Demo").Range("DemoDept")
If CheckBoxEntity.Value = True Then Set NewFillRange =
Worksheets("Demo").Range("DemoDeptByEntity")

If CheckBoxDept.Value = True Then
ComboBoxDept.Visible = True
If ComboBoxEntity.Value = "<" Then Set NewFillRange =
Worksheets("Demo").Range("DemoDept") 'Show ALL depts

With Worksheets("RFJ").ComboBoxDept
.ListFillRange = NewFillRange.Address(external:=True)
End With


Application.Goto Reference:="R12C14"
Application.Goto Reference:="R5C4"

' All Departments Selected
ElseIf CheckBoxDept.Value = False Then
ComboBoxDept.Visible = False
Application.Goto Reference:="R12C14"
ActiveCell.FormulaR1C1 = "<"
Application.Goto Reference:="R5C4"
End If
End Sub

Where do you put a Public subroutine? It it in the "This Workbook"? How do
you call it in a subroutine? I tried application.Run "Workbookname!Newtest",
but got an error regarding a macro.