Home |
Search |
Today's Posts |
|
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]() 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
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]() 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
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]() 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 |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
How do I pull data from multi sheets into one? | Excel Discussion (Misc queries) | |||
Summary of data - multi sheets | Excel Worksheet Functions | |||
add values using vlookup over multi sheets | Excel Discussion (Misc queries) | |||
Sum Array Formula Across Multi Sheets | Excel Programming | |||
Loop across Sheets and number of sheets | Excel Programming |