Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Do..Loop in multi sheets


Hi all,
I am writing a do loop vba, it is fine for applying one sheet. Now I
want to write vba to automate the do loop program for several sheets.
How can I do it?

The following program is only appling to one sheet:
Sub Sub_total()
Range("J2").Select
Do While IsEmpty(ActiveCell.Offset(0, -6)) = False
ActiveCell.FormulaR1C1 = _

"=IF(RC[-8]<R[1]C[-8],SUMIF(R2C[-8]:RC[-8],RC[-8],R2C[-1]:RC[-1]),"""")"
ActiveCell.Offset(1, 0).Select
Loop
End Sub

I tried the follwoing code, but it failed.

Sub Sub_total2l()
For Each sh In ActiveWorkbook.Worksheets
With sh
Range("J2").Select
Do While IsEmpty(ActiveCell.Offset(0, -6)) = False
ActiveCell.FormulaR1C1 = _

"=IF(RC[-8]<R[1]C[-8],SUMIF(R2C[-8]:RC[-8],RC[-8],R2C[-1]:RC[-1]),"""")"
ActiveCell.Offset(1, 0).Select
Loop
End With
Next sh
End Sub

norika


--
norika
------------------------------------------------------------------------
norika's Profile: http://www.excelforum.com/member.php...fo&userid=4878
View this thread: http://www.excelforum.com/showthread...hreadid=374112

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Do..Loop in multi sheets


Thank you. It works.
I have a minor question. In my case, vba applies for all sheets i
active workbook. Is it possible to exclude some sheets not applyin
vba?

TIA

norik

--
norik
-----------------------------------------------------------------------
norika's Profile: http://www.excelforum.com/member.php...nfo&userid=487
View this thread: http://www.excelforum.com/showthread.php?threadid=37411

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Do..Loop in multi sheets


Add the following line
sh.Select
after line 2 in your second sub.

It should be

Sub Sub_total2l()
For Each sh In ActiveWorkbook.Worksheets
sh.Select
With sh
.Range("J2").Select
Do While IsEmpty(ActiveCell.Offset(0, -6)) = False
ActiveCell.FormulaR1C1 = _
"=IF(RC[-8]<R[1]C[-8],SUMIF(R2C[-8]:RC[-8],RC[-8],R2C[-1]:RC[-1]),"""")"
ActiveCell.Offset(1, 0).Select
Loop
End With
Next sh
End Sub



Manges

--
mangesh_yada
-----------------------------------------------------------------------
mangesh_yadav's Profile: http://www.excelforum.com/member.php...fo&userid=1047
View this thread: http://www.excelforum.com/showthread.php?threadid=37411

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
How do I pull data from multi sheets into one? Jami Excel Discussion (Misc queries) 2 October 22nd 09 04:53 PM
Summary of data - multi sheets dan Excel Worksheet Functions 0 September 13th 06 08:17 PM
add values using vlookup over multi sheets Noemi Excel Discussion (Misc queries) 15 October 23rd 05 05:42 PM
Sum Array Formula Across Multi Sheets SMS - John Howard Excel Programming 2 January 17th 05 01:37 PM
Loop across Sheets and number of sheets Raj[_8_] Excel Programming 2 December 18th 03 09:18 AM


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