@ MarvinP

Originally Posted by
MarvinP
............................
?range("TestRange"). ' when you type the period look at all the possible stuff that is available!!!
..........................................
Try to understand all the different words that can come after the period and this is where you will become an expert with VBA and Object Based languages.
…. You bet – I have been learning for about a year and am still amazed how many “things” can be “got at” after hitting .Dot after the Range Object!!
@ MarvinP

Originally Posted by
MarvinP
..... I discovered I could write
Range(Cells(4,"B"),Cells(7,"F")) and this seemed to work........
…. That possibility of combining Letters and number conventions was along my Post #12 and a point worth emphasizing… ( P.s you are just doing a quick demo there so have missed out the often importand worksheet qualifier I guess: ws.Range(ws.Cells(4,"B"),ws.Cells(7,"F")) )
………………………………………………………………………………
@ FDibbins

Originally Posted by
FDibbins
Thanks for the assist and advice guys, really appreciated - now, all I have to do is try and remember this stuff…..
. It is a bit of an honor to help you. If I can indulge a last time, and try to keep it simple as I can…
. 1 ) in any spare or new file put some stuff, formatting etc in first cell, such as…
Using Excel 2007
. 1 a) Make sure your file is saved ( so resave it ) as “With macros” ( .xlsm )
. 2 ) click Alt + F11
. 2a) A big Module Window should should come up ( If not select .. Insert … Module )
. 3) copy and paste in that window the following code
Option Explicit
Sub RangeObject()
10 'Range Object Method, Properties etc. Demo
20 Dim rng As Range
30 Set rng = ThisWorkbook.Worksheets.Item(1).Range("A1") 'Refers to A1 in the First Sheet ( That is the first left Tab Sheet)
40 'Click in the left Margin parallel to End Sub at the end of this code. End Sub Turns Brown/Orange and a Brown/Orange circle appears wher you clicked
50 'Then run the code. ( Click anywhere in this code and hit F5 ). End Sub turns Yellow, indicating that the code has paused
60 'Highlight either of the two rng above. Hit Shift + F9. Click Add ( or sililar ). You get The Range Object shown in the "Watch Window"
70 'Click on the + Box, - then some of the others + boxes - it never seems to end !!!!!!
End Sub
.4 ) 'Click in the left Margin parallel to End Sub at the end of this code. End Sub should turn Brown/Orange and a Brown/Orange circle appears where you clicked
.5) 'Then run the code. ( Click anywhere in this code and hit F5 ). End Sub turns Yellow, indicating that the code has paused
.6) 'Highlight either of the two rng
.7 ) Hit Shift + F9. Click Add ( or similar ). You get, + rng , your Range Object , shown in what is the "Watch Window"
.8) Click on the + Box, - then some of the others + boxes - it never seems to end. !! For example you will find “anything” listed by Value2 ( which is the most fundamental underlying form of what is there, I think ) I have tried sometimes , to find other stuff, – it is all there , but can take a while!!!!!
……………………………………………………………………….

Originally Posted by
FDibbins
…I have been taking memory pills to try and help my failing memory..

.. I sympathize, it is certainly very daunting. I have started a few “Learing about Range Objects” Threads” myself, here and elsewhere:
http://www.mrexcel.com/forum/excel-q...anomaly-2.html
.. maybe a last bit of mindless fun…. as I know you are an animal lover. Here is a real Donkey of an idea. Lets take the simple code Line to do what you want ( your original example code to pt 50 in B2 to D4 )
ws2.Range("B2:D4").Value = 50
. and let’s say we want to stay with this basic form, but we have the column numbers, 2 and 4 in variables, lB and lD rather than having the string letters B and D.
. We can get those string letters by a tedious bit of manipulation of the Cell Address for any cell in those columns, - Lets say in the first row Cells( 1, lB ) and cells( 1, lD )
Then we have a real Donkey of a code Line:
ws2.Range("" & Left(Replace(ws2.Cells(1, lB).Address, "$", "", , 1), (InStr(Replace(ws2.Cells(1, lB).Address, "$", "", , 1), "$") - 1)) & "2:" & Left(Replace(ws2.Cells(1, lD).Address, "$", "", , 1), (InStr(Replace(ws2.Cells(1, lD).Address, "$", "", , 1), "$") - 1)) & "4").Value = 50
. I hope you Don’t like it. I can't think of any reason you might want to use this insted of the endless other ways discussed. ( I would be worried for your sanity if you did like ! )
. I think it’s great. I will probably use it from now on in codes I do.
Alan
'
Sub BonkeyDonkeyFDibbins() 'http://www.excelforum.com/excel-programming-vba-macros/1102805-learing-about-range-objects.html
Dim ws2 As Worksheet: Set ws2 = ThisWorkbook.Worksheets("Sheet2")
Let ws2.Range("B2:D4").Value = 50
ws2.Range("B2:D4").ClearContents
'Variables for the column indices and the column Letters
Dim Bonkey As String, Donkey As String 'The Letters we want should go in 'ere
Dim lB As Long, lD As Long: Let lB = 2: Let lD = 4 'The indicies we have for the columns
'Get a Donkey
Let Donkey = ws2.Cells(1, lD).Address 'Returns $D$1
Let Donkey = Replace(Donkey, "$", "", , 1) 'Returns D$1
Let Donkey = Left(Donkey, (InStr(Donkey, "$") - 1)) 'Returns D
'or
Let Donkey = Left(Replace(ws2.Cells(1, lD).Address, "$", "", , 1), (InStr(Replace(ws2.Cells(1, lD).Address, "$", "", , 1), "$") - 1))
'and similarly for a Bonkey
Let Bonkey = Left(Replace(ws2.Cells(1, lB).Address, "$", "", , 1), (InStr(Replace(ws2.Cells(1, lB).Address, "$", "", , 1), "$") - 1))
'Donk in Bonk in
Let ws2.Range("" & Bonkey & "2:" & Donkey & "4").Value = 50
'or
Let ws2.Range("" & Left(Replace(ws2.Cells(1, lB).Address, "$", "", , 1), (InStr(Replace(ws2.Cells(1, lB).Address, "$", "", , 1), "$") - 1)) & "2:" & Left(Replace(ws2.Cells(1, lD).Address, "$", "", , 1), (InStr(Replace(ws2.Cells(1, lD).Address, "$", "", , 1), "$") - 1)) & "4").Value = 50
End Sub
Bookmarks