Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 67
Default Can I use array to simplify this code.

Sorry for the mess in the previous posting.

Can I use array to simplify this code.
Appreciate your help. Thanks

sub test()
Dim rngJ As Range
Dim rngK As Range
Dim rngL As Range
..
..
..
For Each Cell In rngK
---code---
next

For Each Cell In rngL
---code--- (same as above)
next

For Each Cell In rngM
---code--- (same as above)
next
..
..
..
end sub

------------------------

Notes: rngK, rngL and rngM located in different sheets.

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 111
Default Can I use array to simplify this code.

Hi,
I'm not sure about an array but you could use a function for the
----code---(same as above) parts of your loop...

Function MyFunction(rngCell as Range) as Range
----code----
End Function

This would simplify your code and reduce duplicity.
Hth,
OJ

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 20
Default Can I use array to simplify this code.

Hi broogle,

Try something like...

Sub test()

Dim rngArr(3) As Variant
Dim rng As Variant

' populate the array
Set rngArr(1) = Worksheets(1).Range("A1:A5")
Set rngArr(3) = Worksheets(1).Range("C1:C5")

For Each rng In rngArr
' because we have declared a variant array, we can test for empty members
If Not IsEmpty(rng) Then
' do something... (place your own codew here)
MsgBox rng.Address
End If
Next

End Sub

Ed Ferrero

Can I use array to simplify this code.
Appreciate your help. Thanks

sub test()
Dim rngJ As Range
Dim rngK As Range
Dim rngL As Range
.
.
.
For Each Cell In rngK
---code---
next

For Each Cell In rngL
---code--- (same as above)
next

For Each Cell In rngM
---code--- (same as above)
next
.
.
.
end sub

------------------------

Notes: rngK, rngL and rngM located in different sheets.



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Can I use array to simplify this code.

You received two good answers to your original post.

--
Regards,
Tom Ogilvy

"broogle" wrote in message
oups.com...
Sorry for the mess in the previous posting.

Can I use array to simplify this code.
Appreciate your help. Thanks

sub test()
Dim rngJ As Range
Dim rngK As Range
Dim rngL As Range
.
.
.
For Each Cell In rngK
---code---
next

For Each Cell In rngL
---code--- (same as above)
next

For Each Cell In rngM
---code--- (same as above)
next
.
.
.
end sub

------------------------

Notes: rngK, rngL and rngM located in different sheets.



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
Can I simplify a VB code?????? hoyos Excel Discussion (Misc queries) 1 November 6th 09 09:06 PM
Simplify code Inkel Excel Worksheet Functions 3 March 27th 09 05:52 PM
Need to simplify code alexwren Excel Discussion (Misc queries) 7 August 15th 06 08:07 PM
Simplify syntax of a Sum(IF... Array JustMe602 Excel Worksheet Functions 4 October 7th 05 05:49 AM
Help to simplify code. Michael Beckinsale Excel Programming 0 September 2nd 03 10:26 AM


All times are GMT +1. The time now is 12:30 AM.

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"