PC Review


Reply
Thread Tools Rate Thread

Declaring variables for use in a Module

 
 
Ayo
Guest
Posts: n/a
 
      17th Mar 2010
Is there a way to declare these statement within a Module so that I don't
have to do it in every Subroutine in the Module?

Set errorWS = Worksheets("Error_MarketList")
Set bulkuploadWS = Worksheets("Bulkupload Result")

Right now I have this:

Private Sub cmdbuildBulkUpload_Click()
Set errorWS = Worksheets("Error_MarketList")
errorWS_lastRow = errorWS.Cells(Rows.Count, "A").End(xlUp).Row

Private Sub cmdupdateDates_Click()
Set errorWS = Worksheets("Error_MarketList")
errorWS_lastRow = errorWS.Cells(Rows.Count, "A").End(xlUp).Row

Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As
Boolean)
Set siteWS = Worksheets("Site Milestone Dates")
Set errorWS = Worksheets("Error_MarketList")
errorWS_lastRow = errorWS.Cells(Rows.Count, "A").End(xlUp).Row

Private Sub cmdupdateMarketlist_Click()
Set updateWS = Worksheets("Updated_MarketList")
Set errorWS = Worksheets("Error_MarketList")
errorWS_lastRow = errorWS.Cells(Rows.Count, "A").End(xlUp).Row
updateWS_lastRow = updateWS.Cells(Rows.Count, "A").End(xlUp).Row - 2

Sub changeMarketList()
Set errorWS = Worksheets("Error_MarketList")
Set updateWS = Worksheets("Updated_MarketList")

Sub build_BulkUpload(Sdate As String, Sstatus As String, cRow As Integer)
Dim siteRow As Long
Dim bulkuploadWS As Worksheet, errorWS As Worksheet
Set errorWS = Worksheets("Error_MarketList")
Set bulkuploadWS = Worksheets("Bulkupload Result")

 
Reply With Quote
 
 
 
 
Ryan H
Guest
Posts: n/a
 
      17th Mar 2010
You could make them a Public variable.

Put this in a standard module.

Public errorWS As Worksheet
Public bulkuploadWS As Worksheet

Keep in mind this only declares the variable. You still need to set a
worksheet to it. Maybe you could use the Workbook Open Event.

Private Sub Workbook_Open()

Set errorWS = Worksheets("Error_MarketList")
Set bulkuploadWS = Worksheets("Bulkupload Result")

End Sub

At this point you can use your errorWS and bulkuploadWS variables in your
procedures. Note: If anywhere in your procedures you use the End method
your public variable will have to be re Set.

Hope this helps! If so, let me know, click "YES" below.


--
Cheers,
Ryan


"Ayo" wrote:

> Is there a way to declare these statement within a Module so that I don't
> have to do it in every Subroutine in the Module?
>
> Set errorWS = Worksheets("Error_MarketList")
> Set bulkuploadWS = Worksheets("Bulkupload Result")
>
> Right now I have this:
>
> Private Sub cmdbuildBulkUpload_Click()
> Set errorWS = Worksheets("Error_MarketList")
> errorWS_lastRow = errorWS.Cells(Rows.Count, "A").End(xlUp).Row
>
> Private Sub cmdupdateDates_Click()
> Set errorWS = Worksheets("Error_MarketList")
> errorWS_lastRow = errorWS.Cells(Rows.Count, "A").End(xlUp).Row
>
> Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As
> Boolean)
> Set siteWS = Worksheets("Site Milestone Dates")
> Set errorWS = Worksheets("Error_MarketList")
> errorWS_lastRow = errorWS.Cells(Rows.Count, "A").End(xlUp).Row
>
> Private Sub cmdupdateMarketlist_Click()
> Set updateWS = Worksheets("Updated_MarketList")
> Set errorWS = Worksheets("Error_MarketList")
> errorWS_lastRow = errorWS.Cells(Rows.Count, "A").End(xlUp).Row
> updateWS_lastRow = updateWS.Cells(Rows.Count, "A").End(xlUp).Row - 2
>
> Sub changeMarketList()
> Set errorWS = Worksheets("Error_MarketList")
> Set updateWS = Worksheets("Updated_MarketList")
>
> Sub build_BulkUpload(Sdate As String, Sstatus As String, cRow As Integer)
> Dim siteRow As Long
> Dim bulkuploadWS As Worksheet, errorWS As Worksheet
> Set errorWS = Worksheets("Error_MarketList")
> Set bulkuploadWS = Worksheets("Bulkupload Result")
>

 
Reply With Quote
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Declaring variables in Module vs. Public =?Utf-8?B?SmVmZg==?= Microsoft Excel Misc 5 19th Nov 2007 08:27 PM
Declaring Variables at Module level and Procedure level =?Utf-8?B?R3JhZW1l?= Microsoft Access VBA Modules 5 28th Feb 2007 03:31 PM
Declaring Variables Brad Microsoft Excel Programming 3 12th May 2004 08:13 PM
Declaring variables HHickey Microsoft Dot NET Framework 1 13th Nov 2003 04:39 PM
Declaring variables Pedro Microsoft Excel Programming 1 13th Nov 2003 03:32 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 01:35 PM.