Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4
Default Coding Format and Organization - VBA in Excel

I wrote an Excel macro for departmental use. It used 8 input columns
(A - H) and 6 result columns (I - N). Everything worked fine for a
while. Then the inevitable 'change' came up. It was to resequence
the columns and add a couple of new columns for input. I had been
using the following format type of code in my macro.

Range("I16") = (Range("E16") / Range("F16")) * 100
Range("J16") = Range("I16") * Range("G16")
Set rStrt = Worksheets("tMain").Range("a6")
dSalary = rStrt.Offset(wIdx, 1)
lAmount = rStrt.Offset(wIdx, 2)

The user wants a new column prior to column 'F'. I now have to go
into the code and change all references to column F and beyond in all
moves and calculations.

Should I have defined constants and used the 'offset' format like:

CONST CURSALARY as Long = 5 'Column E
Range("I16") = rStrt.Offset(curRow, CURSALARY) / Range("F16")) *
100


What's the best way to avoid this problem? How do the PRO's do it?

Thanks,

tt
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 968
Default Coding Format and Organization - VBA in Excel

One excellent approach is to used named ranges as anchor points. Then when
your anchors get moved you dont have to change your code.

so your VBA range reference would be of the form Range("CurSalary"). You can
use .Resize , .Offset , .End(XLup) etc with this as required.

But yes it is also good practice to define constants separately.

Charles
______________________
Decision Models
FastExcel Version 2 now available.
www.DecisionModels.com/FxlV2WhatsNew.htm

"TinyTim" wrote in message
...
I wrote an Excel macro for departmental use. It used 8 input columns
(A - H) and 6 result columns (I - N). Everything worked fine for a
while. Then the inevitable 'change' came up. It was to resequence
the columns and add a couple of new columns for input. I had been
using the following format type of code in my macro.

Range("I16") = (Range("E16") / Range("F16")) * 100
Range("J16") = Range("I16") * Range("G16")
Set rStrt = Worksheets("tMain").Range("a6")
dSalary = rStrt.Offset(wIdx, 1)
lAmount = rStrt.Offset(wIdx, 2)

The user wants a new column prior to column 'F'. I now have to go
into the code and change all references to column F and beyond in all
moves and calculations.

Should I have defined constants and used the 'offset' format like:

CONST CURSALARY as Long = 5 'Column E
Range("I16") = rStrt.Offset(curRow, CURSALARY) / Range("F16")) *
100


What's the best way to avoid this problem? How do the PRO's do it?

Thanks,

tt



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
Organization Chart in Excel 2003 garbuckle Excel Discussion (Misc queries) 0 March 13th 09 03:36 PM
Tree organization in excel Francisco Excel Discussion (Misc queries) 6 September 12th 07 04:56 PM
where can I get organization chart add-in for Excel 2000? kturvey Excel Discussion (Misc queries) 1 July 26th 07 05:58 PM
Excel Data Re-Organization Freedle Beetle Excel Discussion (Misc queries) 1 December 6th 05 07:17 PM
How do i set up an organization chart in Excel? rox Charts and Charting in Excel 1 December 30th 04 06:11 PM


All times are GMT +1. The time now is 08:46 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"