Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
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.


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 523
Default Call Subroutine in Excel

Put them in a module.

In the VB window, right click your project and insert module. These two
macros show you how to call a piece of code, as the second calls the first:
Sub test()

MsgBox "Hello"

End Sub

Sub test2()

Call test

End Sub


"DogLover" wrote:

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.


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 37
Default Call Subroutine in Excel

I see how that part works. However, I get an error when my module to the code

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

I think I may need to pass CheckBoxEntity.Value to the subroutine from the
call statement, but I'm not sure.


"Sam Wilson" wrote:

Put them in a module.

In the VB window, right click your project and insert module. These two
macros show you how to call a piece of code, as the second calls the first:
Sub test()

MsgBox "Hello"

End Sub

Sub test2()

Call test

End Sub


"DogLover" wrote:

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.


  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 523
Default Call Subroutine in Excel

You can pass variables as follows:

Sub test(byval strDemo as string)

MsgBox "Hello " & strDemo

End Sub

Sub test2()

dim myStr as string
myStr = "Sam"

Call test(myStr)

End Sub


"DogLover" wrote:

I see how that part works. However, I get an error when my module to the code

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

I think I may need to pass CheckBoxEntity.Value to the subroutine from the
call statement, but I'm not sure.


"Sam Wilson" wrote:

Put them in a module.

In the VB window, right click your project and insert module. These two
macros show you how to call a piece of code, as the second calls the first:
Sub test()

MsgBox "Hello"

End Sub

Sub test2()

Call test

End Sub


"DogLover" wrote:

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.


Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Call a subroutine using variable subroutine name dhstein Excel Discussion (Misc queries) 3 July 26th 09 08:28 PM
call Excel subroutine from Sql Server? news.microsoft.com[_15_] Excel Programming 0 September 17th 08 06:31 PM
Can't call a subroutine donwb Excel Programming 3 August 6th 08 05:05 AM
Call subroutine from another workbook DejaVu[_55_] Excel Programming 2 November 3rd 05 04:12 PM
Call Subx for excel 97 Add-In subroutine Dave D-C[_3_] Excel Programming 4 March 2nd 05 08:05 PM


All times are GMT +1. The time now is 02:47 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"