Home |
Search |
Today's Posts |
|
#1
![]()
Posted to microsoft.public.excel.misc
|
|||
|
|||
![]()
yeah, it works!
thanx "Jim Thomlinson" wrote: There is an error in your range... a90:a92,a94:101,a105:a115 a94:A101??? so try this... Private Sub CommandButton15_Click() Dim rng As Range Dim myrng As Range Set myrng = Range("a90:a92,a94:a101,a105:a115") For Each rng In myrng MsgBox rng.Address & vbCrLf & rng.Value Next rng End Sub -- HTH... Jim Thomlinson "peyman" wrote: hi Jim, I have still the same error!!!the code is not working "Jim Thomlinson" wrote: Get rid of the word me. Since you are coding a command button Me will refer to the command button and not the sheet. So try this... Private Sub CommandButton15_Click() Dim rng As Range Dim myrng As Range Set myrng = Range("a90:a92,a94:101,a105:a115") For Each rng In myrng MsgBox rng.Address & vbCrLf & rng.Value Next rng End Sub Since your code resides within a sheet any time you use range without a sheet referenced it will refer to the sheet that the code is in. -- HTH... Jim Thomlinson "peyman" wrote: hi Jim, i used the code as: Private Sub CommandButton15_Click() Dim rng As Range Dim myrng As Range Set myrng = Me.Range("a90:a92,a94:101,a105:a115") For Each rng In myrng MsgBox rng.Address & vbCrLf & rng.Value Next rng End Sub but there is an error on line "Set myrng = Me.Range("a90:a92,a94:101,a105:a115")" with this message: method 'range' of object '_worksheet' failed "Jim Thomlinson" wrote: oops... dim rng as range dim myRng as range 'Booboo here Set myRng=Me.Range("a3:a5,a7:a19,a22:a33") for each rng in myRng msgbox rng.Address & vbcrlf & rng.value next rng -- HTH... Jim Thomlinson "Jim Thomlinson" wrote: It initializes a range object made up of the cells a3:a5,a7:a19,a22:a33. Try this... dim rng as range dim myRng as rng Set myRng=Me.Range("a3:a5,a7:a19,a22:a33") for each rng in myRng msgbox rng.Address & vbcrlf & rng.value next rng -- HTH... Jim Thomlinson "peyman" wrote: hi, Can anybody tell me what the following code does? Set myRng=Me.Range("a3:a5,a7:a19,a22:a33") thanks |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
question in VB codes | Excel Discussion (Misc queries) | |||
Need some help with codes | Excel Discussion (Misc queries) | |||
codes, codes, codes... | Excel Discussion (Misc queries) | |||
Bar Codes | Excel Discussion (Misc queries) | |||
Zip Codes | Excel Discussion (Misc queries) |