Results 1 to 8 of 8

Looping through worksheets

Threaded View

  1. #1
    Forum Contributor
    Join Date
    02-24-2010
    Location
    BC, Canada
    MS-Off Ver
    Excel 2010
    Posts
    174

    Looping through worksheets

    Hi,

    I am trying to perform the same actions on all of the worksheets in my workbook. I have tried the following two codes but neither of them work:

    Dim ws As Integer
    
    For ws = 1 To Worksheets.Count
     Sheets(ws).Select
      Cells(4, 4) = RYear
      Range("A5") = "setdefault Period=" & RYear & "00:" & RYear & "13"
      Range("A6") = "setdefault Period_from=" & RYear & "00"
      Range("A7") = "setdefault Period_to=" & RYear & "13"
      Range("B16") = Range("D3") & Range("D4")
      Range("B17") = "Report run on " & Format(Date, "mmm dd, yyyy")
    Next ws
    Dim ws As Worksheet
    
    For Each ws In ActiveWorkbook.Sheets
     Cells(4, 4) = RYear
     Range("A5") = "setdefault Period=" & RYear & "00:" & RYear & "13"
     Range("A6") = "setdefault Period_from=" & RYear & "00"
     Range("A7") = "setdefault Period_to=" & RYear & "13"
     Range("B16") = Range("D3") & Range("D4")
     Range("B17") = "Report run on " & Format(Date, "mmm dd, yyyy")
    Next
    I tried that last one with "next" and "next ws".

    Neither of these are making all of the changes that are specified. Any thoughts?

    Thank you.
    Last edited by The Phil; 01-17-2014 at 03:23 PM.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Looping through worksheets
    By terkel in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 11-25-2008, 03:54 AM
  2. Looping through worksheets
    By terkel in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 10-17-2008, 02:53 AM
  3. Looping through Worksheets
    By Steve in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 07-12-2005, 03:05 PM
  4. Looping across worksheets
    By Ramthebuffs in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 06-19-2005, 12:52 AM
  5. Looping through Worksheets
    By Kirk P. in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 02-07-2005, 02:06 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1