|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
Get inside! Sample the range of functionality easily built with JMSL Library for Time Series Data Analysis, Heat Maps, Portfolio Optimization, Monte Carlo Simulation, Stock Price Charting and more. Download Now! |
|
#1
|
|||
|
|||
|
Selecting Multiple Ranges using Cells(i, j) Notation
I am trying to select multiple ranges in an Excel macro. The ranges are being generated from values of integers created elsewhere.
I have seen examples to select multiple ranges using the standard "A1:A5" notation, but cannot get it to work for the Cells(i, j) notation. Here is the offending code. Code:
Set varRangeSelect1 = Range(Cells(10, 2), Cells(11, 2))
Set varRangeSelect2 = Range(Cells(13, 2), Cells(intCountRow, 2))
Set varRangeSelect3 = Union(Range(varRangeSelect1), Range(varRangeSelect2))
Range(varRangeSelect).Select
When the last line is executed, I get the following error: Run Time Error 104 Method 'Range' of object '_Global' failed Of course the help menu in Visual Basic for Excel is most unhelpful. Any suggestions on how I can make this work would be greatly appreciated. Thanks, Michael Pepera |
|
#2
|
||||
|
||||
|
Are you sure it shouldn't be:
Code:
Range(varRangeSelect3).Select |
|
#3
|
|||
|
|||
|
Yes you are right. However, the problem still remains the same!
Thanks for the reply, Michael Pepera |
|
#4
|
||||
|
||||
|
This worked for me:
Set varRangeSelect1 = Range(Cells(10, 2), Cells(11, 2)) Set varRangeSelect2 = Range(Cells(13, 2), Cells(intCountRow, 2)) Set varRangeSelect3 = Union(varRangeSelect1, varRangeSelect2) varRangeSelect.Select This would also work: Set varRangeSelect3 = Union(Range(Cells(10,2), Cells(11,2)), Range(Cells(13,2), Cells(intCountRow,2))) varRangeSelect3.Select Hope that helps you out. |
|
#5
|
|||
|
|||
|
Thanks for the help! Now that I look back at the code, I ended doing something slightly different in order to work around the problem.
However, it is good to know how this will function for the future. |
![]() |
| Viewing: Dev Shed Forums > Programming Languages - More > Visual Basic Programming > Selecting Multiple Ranges using Cells(i, j) Notation |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|