#1   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 189
Default question on VB codes

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
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
question in VB codes peyman Excel Discussion (Misc queries) 1 September 19th 07 11:54 PM
Need some help with codes Tom Excel Discussion (Misc queries) 2 August 16th 07 01:09 AM
codes, codes, codes... jatman Excel Discussion (Misc queries) 2 August 20th 06 07:30 AM
Bar Codes [email protected] Excel Discussion (Misc queries) 4 August 31st 05 08:12 AM
Zip Codes Queen Excel Discussion (Misc queries) 3 February 18th 05 02:47 PM


All times are GMT +1. The time now is 01:20 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"