Activate Multiple Ranges
Hello Andibevan,
For myself I see 2 possibilities:
A. For Sheet3, Column B should contain a string like "c1:d1,c3:d3" or
"c1:d1;c3:d3" (depending on your local setting);
in this case the complete range is selected at once by
Range(Var_Range).Select
B. If this is not possible, you could construct this string in code, by
adding a subloop
in which - as long as the sheet name in column A remains the same - the
value
of column is added to the former string, divided by ',' or ';'
In addition may I give some 'grammatical' hints?
- I think the line ' Const_Range = Sheet1.Range("a" & Start_r & ":b" &
last_r) '
should be preceded by the key word 'Set' in order to create a range object
- the number of rows in Sheet1 could also be determined by the statement:
last_r = Sheet1.Range("A1").CurrentRange (or whereever you start)
- your For/Next-loop could be more easily read (and with less lines of code)
when you would have written:
For r = 1 to last_r 'r is automatically initiated here
' (etc.)
' you don't need an If-statement here to test r
Next
- you'd better use ' Cells(r, 1).Value ' for ' Cells(r, 1) ' ,
although Value is the default property for a Range-object
- you may skip one line of code (and you get quicker execution of the code),
while you need not select a worksheet to extract data from it:
' skip Sheet1.Activate
Var_Sheet = Sheet1.Cells(r, 1)
Var_Range = Sheet1.Cells(r, 2)
Please do apologize these teaching inclinations!
Many greetings,
Peter
|