Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 269
Default For Next issue with repeated procedure

set your ranges in an array

Dim rng(6) As String
rng(1) = "A1:A9"
rng(2) = "A11:A20"
rng(3) = "A30:A34"
rng(4) = "A40:A48"
rng(5) = "A50:A59"
rng(6) = "A65:A69"

n = 6

For i = 1 To n
ActiveCell.Range(rng(i)).Select
Selection.Copy
Selection.PasteSpecial Paste:=xlPasteValues
Application.CutCopyMode = False
Next i

Using the ActiveCell.Range method give you a relative reference. If you
want the ranges to always be A1:A9, .. etc, remove the ActiveCell. and just
use Range(rng(i)).select
--
If this helps, please remember to click yes.


"ccfcrup" wrote:

I have the procedure below. Basically I don't want to have
interminable lines of code when all I am doing is repeating the same
procedure on a differnet range. How can I write the procedure that it
loops through the procedure with the 6 different ranges

rng1 = "A1:A9"
rng2 = "A11:A20"
Rng3 = "A30:A34"
Rng4 = "A40:A48"
Rng5 = "A50:A59"
Rng6 = "A65:A69"


n = 6

For i = 1 To n

ActiveCell.Range(rng(i)).Select
Selection.Copy
Selection.PasteSpecial Paste:=xlPasteValues
Application.CutCopyMode = False
Next i

Thanks

Rup
.

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
For Next issue with repeated procedure Dave Peterson Excel Programming 0 December 11th 09 08:25 PM
How to jump from a Form procedure to a Workbook or Module procedure? T. Erkson Excel Programming 4 January 25th 07 07:15 PM
procedure call error issue Student Excel Programming 2 October 24th 06 04:28 PM
Workbook_open procedure issue when two spreadsheets are opened Gardfd Excel Programming 2 April 6th 06 07:16 PM
Printing text in a repeated cell/row that is longer than repeated Valerie Dyet Excel Discussion (Misc queries) 1 February 13th 06 03:27 AM


All times are GMT +1. The time now is 08:54 PM.

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

About Us

"It's about Microsoft Excel"