liquidmettle
New Member
- Joined
- May 23, 2013
- Messages
- 48
Hello Everyone,
I don't know if I am violating forum rules with this post, so if I am, please let me know and moderators act accordingly.
Recently I posted a topic called http://www.mrexcel.com/forum/excel-...-applications-help-dashboard.html#post3504562.
SergioMabres gave me an excellent answer but I want to understand exactly what his VBA code is telling me (in as plain of english as I can) so that I can reverse engineer it to work in the spreadsheets I need to at work.
1st:
Sergio's test file: https://dl.dropboxusercontent.com/u/23094164/liquidmettle1.xlsm
This file's macro does exactly what I need it to do. I.E. Copy a set of named ranges across various sheets so that a layman can update a data tracking dashboard without tedious re-entry of past data.
2nd:The Macro code:
Sub moveforward()
'
' Copies range2 in 1, 3 in 2, 4 in 3 and erases 4
' Ranges are not rectangular and non continuos
'
Dim i, j, k As Integer
For k = 2 To 4
For i = 1 To Range("range" & (k)).Areas.Count
For j = 1 To Range("range" & (k)).Areas(i).Cells.Count
' Copies values cell by cell, and as long as the ranges
' are similar (same shape and size) ther is not a problem
Range("range" & (k - 1)).Areas(i)(j).Cells(1, 1) = Range("range" & (k)).Areas(i)(j).Cells(1, 1)
Next j
Next i
Next k
' Erase sheet 4
Range("range4").ClearContents
End Sub
In the dashboard for work, I have 4 named ranges covering this non-contiguous range (the reason I don't just highlight the whole block between m17:x134 is that the rows in-between have formulas that I cannot have erased):
M17:X18, M21:X22, M25:X26, M29:X30, M33:X34, M37:X38, M41:X42, M45:X46, M49:X50, M53:X54, M57:X58, M61:X62, M65:X66,M69:X70, M73:X74, M77:X78, M81:X82, M85:X86, M89:X90, M93:X94, M97:X98, M101:X102, M105:X106, M109:X110, M113:X114, M117:X118, M121:X122, M125:X126, M129:X130, M133:X134.
The range listed above are the same in all 4 of the sheets (no variation on location), and I made one Named Range per sheet (by control selecting the ranges listed above). My sheet names, as in Sergio's test file, are the same, being 1,2,3, and 4.
His named ranges (which I could change mine to mimic) are Range 1, Range 2, Range 3, and Range 4.
Mind you Sergio's code does what I want in his test file. But I have no idea what the line "Dim i, j, k As integer" is actually saying, and the rest seems to go into worse comprehension from there.
Can anyone walk me through this in plain English so that I may be able to apply this macro to the more complex dashboard I am developing at work?
Thank you all so much,
-LM
I don't know if I am violating forum rules with this post, so if I am, please let me know and moderators act accordingly.
Recently I posted a topic called http://www.mrexcel.com/forum/excel-...-applications-help-dashboard.html#post3504562.
SergioMabres gave me an excellent answer but I want to understand exactly what his VBA code is telling me (in as plain of english as I can) so that I can reverse engineer it to work in the spreadsheets I need to at work.
1st:
Sergio's test file: https://dl.dropboxusercontent.com/u/23094164/liquidmettle1.xlsm
This file's macro does exactly what I need it to do. I.E. Copy a set of named ranges across various sheets so that a layman can update a data tracking dashboard without tedious re-entry of past data.
2nd:The Macro code:
Sub moveforward()
'
' Copies range2 in 1, 3 in 2, 4 in 3 and erases 4
' Ranges are not rectangular and non continuos
'
Dim i, j, k As Integer
For k = 2 To 4
For i = 1 To Range("range" & (k)).Areas.Count
For j = 1 To Range("range" & (k)).Areas(i).Cells.Count
' Copies values cell by cell, and as long as the ranges
' are similar (same shape and size) ther is not a problem
Range("range" & (k - 1)).Areas(i)(j).Cells(1, 1) = Range("range" & (k)).Areas(i)(j).Cells(1, 1)
Next j
Next i
Next k
' Erase sheet 4
Range("range4").ClearContents
End Sub
In the dashboard for work, I have 4 named ranges covering this non-contiguous range (the reason I don't just highlight the whole block between m17:x134 is that the rows in-between have formulas that I cannot have erased):
M17:X18, M21:X22, M25:X26, M29:X30, M33:X34, M37:X38, M41:X42, M45:X46, M49:X50, M53:X54, M57:X58, M61:X62, M65:X66,M69:X70, M73:X74, M77:X78, M81:X82, M85:X86, M89:X90, M93:X94, M97:X98, M101:X102, M105:X106, M109:X110, M113:X114, M117:X118, M121:X122, M125:X126, M129:X130, M133:X134.
The range listed above are the same in all 4 of the sheets (no variation on location), and I made one Named Range per sheet (by control selecting the ranges listed above). My sheet names, as in Sergio's test file, are the same, being 1,2,3, and 4.
His named ranges (which I could change mine to mimic) are Range 1, Range 2, Range 3, and Range 4.
Mind you Sergio's code does what I want in his test file. But I have no idea what the line "Dim i, j, k As integer" is actually saying, and the rest seems to go into worse comprehension from there.
Can anyone walk me through this in plain English so that I may be able to apply this macro to the more complex dashboard I am developing at work?
Thank you all so much,
-LM