PC Review


Reply
Thread Tools Rate Thread

Coding Convention

 
 
RussellT
Guest
Posts: n/a
 
      18th Dec 2009
Thanks in advance.
Which of the following ways is the best coding convention and why?
Private Sub()
Sheets("DevData").Range("SourceDev").AdvancedFilter Action:=xlFilterCopy,
CriteriaRange:=Sheets("FilterControl").Range("A28:Y29"), _
CopyToRange:=Sheets("Results").Range("A2:W2"), Unique:=False
end sub
Public Sub FilterDbase_Click()
Dim filtercontrolSheet As Worksheet
Dim resultsSheet As Worksheet
Dim devdataSheet As Worksheet
Set filtercontrolSheet = Sheets("FilterControl")
Set resultsSheet = Sheets("Results")
Set devdataSheet = Sheets("DevData")

devdataSheet.Range("SourceDev").AdvancedFilter Action:=xlFilterCopy,
CriteriaRange:=filtercontrolSheet.Range("A28:Y29"), _
CopyToRange:=resultsSheet.Range("A2:W2"), Unique:=False
End Sub

Public Sub FilterDbase_Click()
Dim SourceRng
Dim CritRng
Dim CopyToRng
Set SourceRng = Sheets("DevData").Range("SourceDev")
Set CritRng = Sheets("FilterControl").Range("A28:Y29")
Set CopyToRng = Sheets("Results").Range("A2:W2")

SourceRng.AdvancedFilter Action:=xlFilterCopy, CriteriaRange:=CritRng, _
CopyToRange:=CopyToRng, Unique:=False
End Sub

 
Reply With Quote
 
 
 
 
Jacob Skaria
Guest
Posts: n/a
 
      18th Dec 2009
I would prefer the last one but with the variables declared as Range coz

1. You are accessing the range object directly
2. Any changes to the code (sheetname or the range reference) at a later
stage would be easy to make ..Just one place to edit and that too at top of
the procedure..

Dim SourceRng As Range
Dim CritRng As Range
Dim CopyToRng As Range

--
Jacob


"RussellT" wrote:

> Thanks in advance.
> Which of the following ways is the best coding convention and why?
> Private Sub()
> Sheets("DevData").Range("SourceDev").AdvancedFilter Action:=xlFilterCopy,
> CriteriaRange:=Sheets("FilterControl").Range("A28:Y29"), _
> CopyToRange:=Sheets("Results").Range("A2:W2"), Unique:=False
> end sub
> Public Sub FilterDbase_Click()
> Dim filtercontrolSheet As Worksheet
> Dim resultsSheet As Worksheet
> Dim devdataSheet As Worksheet
> Set filtercontrolSheet = Sheets("FilterControl")
> Set resultsSheet = Sheets("Results")
> Set devdataSheet = Sheets("DevData")
>
> devdataSheet.Range("SourceDev").AdvancedFilter Action:=xlFilterCopy,
> CriteriaRange:=filtercontrolSheet.Range("A28:Y29"), _
> CopyToRange:=resultsSheet.Range("A2:W2"), Unique:=False
> End Sub
>
> Public Sub FilterDbase_Click()
> Dim SourceRng
> Dim CritRng
> Dim CopyToRng
> Set SourceRng = Sheets("DevData").Range("SourceDev")
> Set CritRng = Sheets("FilterControl").Range("A28:Y29")
> Set CopyToRng = Sheets("Results").Range("A2:W2")
>
> SourceRng.AdvancedFilter Action:=xlFilterCopy, CriteriaRange:=CritRng, _
> CopyToRange:=CopyToRng, Unique:=False
> End Sub
>

 
Reply With Quote
 
Patrick Molloy
Guest
Posts: n/a
 
      18th Dec 2009
I agree - it makes the code much easier to understand, and so making changes
later become easier...not only for you, but for anyone maybe later in the sa

I'd have added a reference to the workbook too, but thats me being picky

with ThisWorkbook
>> Set SourceRng = .Sheets("DevData").Range("SourceDev")
>> Set CritRng = .Sheets("FilterControl").Range("A28:Y29")
>> Set CopyToRng = .Sheets("Results").Range("A2:W2")

End With

"Jacob Skaria" <(E-Mail Removed)> wrote in message
news:C21C8863-8DE9-4450-BE95-(E-Mail Removed)...
> I would prefer the last one but with the variables declared as Range coz
>
> 1. You are accessing the range object directly
> 2. Any changes to the code (sheetname or the range reference) at a later
> stage would be easy to make ..Just one place to edit and that too at top
> of
> the procedure..
>
> Dim SourceRng As Range
> Dim CritRng As Range
> Dim CopyToRng As Range
>
> --
> Jacob
>
>
> "RussellT" wrote:
>
>> Thanks in advance.
>> Which of the following ways is the best coding convention and why?
>> Private Sub()
>> Sheets("DevData").Range("SourceDev").AdvancedFilter Action:=xlFilterCopy,
>> CriteriaRange:=Sheets("FilterControl").Range("A28:Y29"), _
>> CopyToRange:=Sheets("Results").Range("A2:W2"), Unique:=False
>> end sub
>> Public Sub FilterDbase_Click()
>> Dim filtercontrolSheet As Worksheet
>> Dim resultsSheet As Worksheet
>> Dim devdataSheet As Worksheet
>> Set filtercontrolSheet = Sheets("FilterControl")
>> Set resultsSheet = Sheets("Results")
>> Set devdataSheet = Sheets("DevData")
>>
>> devdataSheet.Range("SourceDev").AdvancedFilter Action:=xlFilterCopy,
>> CriteriaRange:=filtercontrolSheet.Range("A28:Y29"), _
>> CopyToRange:=resultsSheet.Range("A2:W2"), Unique:=False
>> End Sub
>>
>> Public Sub FilterDbase_Click()
>> Dim SourceRng
>> Dim CritRng
>> Dim CopyToRng
>> Set SourceRng = Sheets("DevData").Range("SourceDev")
>> Set CritRng = Sheets("FilterControl").Range("A28:Y29")
>> Set CopyToRng = Sheets("Results").Range("A2:W2")
>>
>> SourceRng.AdvancedFilter Action:=xlFilterCopy, CriteriaRange:=CritRng,
>> _
>> CopyToRange:=CopyToRng, Unique:=False
>> End Sub
>>

 
Reply With Quote
 
RussellT
Guest
Posts: n/a
 
      18th Dec 2009
Thanks for the input. I understand the making changes to the code in the
futre would be easier using option #3, but do are any of the formats more
readily identified by vba? thanks again.

"Jacob Skaria" wrote:

> I would prefer the last one but with the variables declared as Range coz
>
> 1. You are accessing the range object directly
> 2. Any changes to the code (sheetname or the range reference) at a later
> stage would be easy to make ..Just one place to edit and that too at top of
> the procedure..
>
> Dim SourceRng As Range
> Dim CritRng As Range
> Dim CopyToRng As Range
>
> --
> Jacob
>
>
> "RussellT" wrote:
>
> > Thanks in advance.
> > Which of the following ways is the best coding convention and why?
> > Private Sub()
> > Sheets("DevData").Range("SourceDev").AdvancedFilter Action:=xlFilterCopy,
> > CriteriaRange:=Sheets("FilterControl").Range("A28:Y29"), _
> > CopyToRange:=Sheets("Results").Range("A2:W2"), Unique:=False
> > end sub
> > Public Sub FilterDbase_Click()
> > Dim filtercontrolSheet As Worksheet
> > Dim resultsSheet As Worksheet
> > Dim devdataSheet As Worksheet
> > Set filtercontrolSheet = Sheets("FilterControl")
> > Set resultsSheet = Sheets("Results")
> > Set devdataSheet = Sheets("DevData")
> >
> > devdataSheet.Range("SourceDev").AdvancedFilter Action:=xlFilterCopy,
> > CriteriaRange:=filtercontrolSheet.Range("A28:Y29"), _
> > CopyToRange:=resultsSheet.Range("A2:W2"), Unique:=False
> > End Sub
> >
> > Public Sub FilterDbase_Click()
> > Dim SourceRng
> > Dim CritRng
> > Dim CopyToRng
> > Set SourceRng = Sheets("DevData").Range("SourceDev")
> > Set CritRng = Sheets("FilterControl").Range("A28:Y29")
> > Set CopyToRng = Sheets("Results").Range("A2:W2")
> >
> > SourceRng.AdvancedFilter Action:=xlFilterCopy, CriteriaRange:=CritRng, _
> > CopyToRange:=CopyToRng, Unique:=False
> > End Sub
> >

 
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
Best Practices - Coding Convention Question Ren Microsoft VB .NET 10 23rd Mar 2006 02:36 PM
# Coding Convention Uncle Ben Microsoft C# .NET 1 7th May 2005 06:55 AM
Coding Convention =?Utf-8?B?RWpheiB1bCBIYXE=?= Microsoft C# .NET 3 9th Dec 2004 08:19 AM
Coding convention for C# Le Hong Son Microsoft C# .NET 1 12th Jan 2004 06:52 AM
Coding convention for C# News.microsoft.com Microsoft Dot NET 1 12th Jan 2004 06:11 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 01:34 AM.