Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default Simple loop in macro

Can someone please help me.

I'm trying to write a script which will go to adjacent cells in row 6
of a PivotTable and replace the existing text with text located in
adjacent cells in a row at another location.

I can achieve this with the following code:

Range("B5").Select
ActiveSheet.PivotTables
("PivotTable1").PivotFields("Date").PivotItems_ ("4/12/2005 -
10/12/2005").Caption = "10/12/05"
Range("C5").Select
ActiveSheet.PivotTables
("PivotTable1").PivotFields("Date").PivotItems_("1 1/12/2005 -
17/12/2005").Caption = "17/12/05"
Range("C5").Select
ActiveSheet.PivotTables
("PivotTable1").PivotFields("Date").PivotItems_("1 8/12/2005 -
24/12/2005").Caption = "24/12/05"

However, I want to write this more efficiently using code which
successively increments each column reference in Row 6 and replacing
with the text in Row 100, where B100 = 10/12/05, C100 = 17/12/05, D100
= 24/12/05.

Can someone kindly help show me how this can be done?

Thanks, Simon

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default Simple loop in macro

Dim cell As Range
Dim n As Long

n = 4
For Each cell In Range("B5:D5")
ActiveSheet.PivotTables("PivotTable1").PivotFields ("Date") _
.PivotItems_(n & "/12/2005 - " & n + 6 & "/12/2005") _
.Caption = n + 6 & "/12/05"
Next cell


--
HTH

Bob Phillips

(remove nothere from email address if mailing direct)

wrote in message
oups.com...
Can someone please help me.

I'm trying to write a script which will go to adjacent cells in row 6
of a PivotTable and replace the existing text with text located in
adjacent cells in a row at another location.

I can achieve this with the following code:

Range("B5").Select
ActiveSheet.PivotTables
("PivotTable1").PivotFields("Date").PivotItems_ ("4/12/2005 -
10/12/2005").Caption = "10/12/05"
Range("C5").Select
ActiveSheet.PivotTables
("PivotTable1").PivotFields("Date").PivotItems_("1 1/12/2005 -
17/12/2005").Caption = "17/12/05"
Range("C5").Select
ActiveSheet.PivotTables
("PivotTable1").PivotFields("Date").PivotItems_("1 8/12/2005 -
24/12/2005").Caption = "24/12/05"

However, I want to write this more efficiently using code which
successively increments each column reference in Row 6 and replacing
with the text in Row 100, where B100 = 10/12/05, C100 = 17/12/05, D100
= 24/12/05.

Can someone kindly help show me how this can be done?

Thanks, Simon



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default Simple loop in macro

Bob

Many thanks for your reply. I've tried what you've said, and this works
for the first cell B5 but then the macro halts and I get an error
message.

What I want it to do after B5 is then move to C5 and replace text with
17/12/05, then move to D5 and replace text with 24/12/05.

Your help would be very much appreciated.

Thanks, Simon

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
simple loop macro jim27[_4_] Excel Programming 1 October 17th 04 07:14 PM
simple loop macro jim27[_3_] Excel Programming 0 October 17th 04 06:40 PM
simple loop macro jim27[_2_] Excel Programming 0 October 17th 04 06:36 PM
simple loop macro jim27 Excel Programming 2 October 17th 04 06:28 PM
Probably missing something simple in loop macro...Please help Jules[_6_] Excel Programming 3 April 15th 04 05:16 AM


All times are GMT +1. The time now is 06:27 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"