Tedious definitions

RET79

Well-known Member
Joined
Mar 19, 2002
Messages
526
Hi. I have a code which works great, but, I would like to make it more readable. It starts off by defining many constants and dynamic ranges. However, I was wondering if someone could help me condense these sort of declarations at the beginning of the code..... take a look !

Dim arrmonth1, arrmonth2, arrmonth3, arrmonth4, _
arrmonth5, arrmonth6, arrmonth7, arrmonth8, _
arrmonth9, arrmonth10, arrmonth11, arrmonth12 As Variant

Dim rngmonth1, rngmonth2, rngmonth3, rngmonth4, _
rngmonth5, rngmonth6, rngmonth7, rngmonth8, _
rngmonth9, rngmonth10, rngmonth11, rngmonth12 As Range

Dim zm1, zm2, zm3, zm4, zm5, zm6, zm7, zm8, zm9, zm10, zm11, zm12 As Long

Set rngmonth1 = Range([D8], [D8].End(xlDown))
Set rngmonth2 = Range([I8], [I8].End(xlDown))
Set rngmonth3 = Range([N8], [N8].End(xlDown))
Set rngmonth4 = Range([S8], [S8].End(xlDown))
Set rngmonth5 = Range([X8], [X8].End(xlDown))
Set rngmonth6 = Range([AC8], [AC8].End(xlDown))
Set rngmonth7 = Range([AH8], [AH8].End(xlDown))
Set rngmonth8 = Range([AM8], [AM8].End(xlDown))
Set rngmonth9 = Range([AR8], [AR8].End(xlDown))
Set rngmonth10 = Range([AW8], [AW8].End(xlDown))
Set rngmonth11 = Range([BB8], [BB8].End(xlDown))
Set rngmonth12 = Range([BG8], [BG8].End(xlDown))

zm1 = rngmonth1.Rows.Count
zm2 = rngmonth2.Rows.Count
zm3 = rngmonth3.Rows.Count
zm4 = rngmonth4.Rows.Count
zm5 = rngmonth5.Rows.Count
zm6 = rngmonth6.Rows.Count
zm7 = rngmonth7.Rows.Count
zm8 = rngmonth8.Rows.Count
zm9 = rngmonth9.Rows.Count
zm10 = rngmonth10.Rows.Count
zm11 = rngmonth11.Rows.Count
zm12 = rngmonth12.Rows.Count

arrmonth1 = rngmonth1
arrmonth2 = rngmonth2
arrmonth3 = rngmonth3
arrmonth4 = rngmonth4
arrmonth5 = rngmonth5
arrmonth6 = rngmonth6
arrmonth7 = rngmonth7
arrmonth8 = rngmonth8
arrmonth9 = rngmonth9
arrmonth10 = rngmonth10
arrmonth11 = rngmonth11
arrmonth12 = rngmonth12


Thanks,
RET79
This message was edited by RET79 on 2002-04-01 06:52
 
Hi guys, have done all the code, but stuck on this bit, the line I am unsure about I will place inside the '''''''' rows, thanks again :



For p = 1 To 12
'Most declarations finished, now let's loop through the files and extract data, one type at a time.
'loop through type 1 months here, source =stakeval& month

Dim Month As Integer
For Month = 3 To rngMonth(p).Rows.Count Step 1
Workbooks.Open Filename:=filepath & rngMonth(p)(Month, 1) & ".xls"
Worksheets(Filesheet).Select

For k = 1 To i - 1
For cellx = 1 To rngcells(p).Rows.Count - 1

'''''''''''''''''''''''''''''''''

Dim arrcells(1 To 12, 255, 41)

arrcells(p, k - 1, cellx - 1) = Cells(rngcells(p)(cellx + 1, 2), rngcells(p)(cellx + 1, 3)).Offset(0, tl8 * (k - 1)).Value
Debug.Print arrcells(p, k - 1, cellx - 1)

''''''''''''''''''''''''''''''

Next cellx
Next k
ActiveWorkbook.Close False
dest.Activate
[B65336].End(xlUp).Offset(1, 0).Select


'''''''''''''''''''''''''
Range(Selection, Selection.Offset(i - 1, rngcells(p).Rows.Count - 2)) = arrcells
''''''''''''''''''''''''''

Next Month

Next p
 
Upvote 0

Excel Facts

Lock one reference in a formula
Need 1 part of a formula to always point to the same range? use $ signs: $V$2:$Z$99 will always point to V2:Z99, even after copying

Forum statistics

Threads
1,213,562
Messages
6,114,326
Members
448,564
Latest member
ED38

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top