+ Reply to Thread
Results 1 to 6 of 6

Macro to cycle through classes and add a date format to a specific cell

  1. #1
    Forum Contributor
    Join Date
    09-07-2010
    Location
    London
    MS-Off Ver
    Excel 2010
    Posts
    358

    Macro to cycle through classes and add a date format to a specific cell

    Hi,

    I am wanting to create a macro to easily fix some documents that I receive every week, there are way way too many classes for me to go through and fix the date manually so I am looking for a bit of help!

    The document looks pretty similar to what's attached, I've just removed all of the private information.

    All I need is a looping macro to cycle through each class and change the date (green box) to have the "Small Date" formatting, bare in mind it must be the UK date layout: 25/01/2019 (dd/mm/yyyy)

    1. The first class always appears on row 16.
    2. The classes are never contain the same amount of people, for example the first one only contains 4 but the next one contains 12...
    3. The Unique TItles are the same for each class (I've surrounded a class in a thick border), for example I've given an example just below "Date" which is "Average SPCD"
    4. Column A is the best column to use for working out the length of each class because the other columns could potentially have missing data

    I've also added a sheet called "WantedAppearance" to show what I am trying to achieve, it should make it very very clear that way, just in case I have explained poorly.

    If you could add some comments to the macro it would be useful because that way I can figure the code out

    I'd appreciate the help Thanks
    Attached Files Attached Files

  2. #2
    Forum Expert
    Join Date
    10-06-2008
    Location
    Canada
    MS-Off Ver
    2007 / 2013
    Posts
    5,520

    Re: Macro to cycle through classes and add a date format to a specific cell

    Please Login or Register  to view this content.
    Last edited by jolivanes; 03-12-2019 at 01:51 AM.

  3. #3
    Forum Contributor
    Join Date
    09-07-2010
    Location
    London
    MS-Off Ver
    Excel 2010
    Posts
    358

    Re: Macro to cycle through classes and add a date format to a specific cell

    Quote Originally Posted by jolivanes View Post
    Sub Maybe()
    Dim heute As String, c As Range
    heute = Format(Date, "dd/mm/yyyy")
    For Each c In Range("L1:L" & Cells(Rows.Count, 12).End(xlUp).Row)
    If c.Value = "Date" Then c.Offset(, 1) = heute
    Next c
    End Sub
    The big problem with that is it's checking every single row is it not? The sheet is huge and it takes quite a long time.

    I managed to figure out one solution:

    Please Login or Register  to view this content.
    Can it be done better?

  4. #4
    Forum Expert
    Join Date
    10-06-2008
    Location
    Canada
    MS-Off Ver
    2007 / 2013
    Posts
    5,520

    Re: Macro to cycle through classes and add a date format to a specific cell

    Re"it takes quite a long time"
    Yes, looping is not normally the way to go in a huge file. I was not aware of the size of the file.
    How long does it take to run?
    Autofilter might be a better way.

  5. #5
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,522

    Re: Macro to cycle through classes and add a date format to a specific cell

    See if this is faster,
    Please Login or Register  to view this content.

  6. #6
    Forum Expert
    Join Date
    10-06-2008
    Location
    Canada
    MS-Off Ver
    2007 / 2013
    Posts
    5,520

    Re: Macro to cycle through classes and add a date format to a specific cell

    Or try like so.
    Please Login or Register  to view this content.
    Last edited by jolivanes; 03-12-2019 at 02:34 AM. Reason: Delete not needed text

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. [SOLVED] VBA macro to cycle through categories and add next date range
    By alexcon in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 02-17-2018, 07:04 AM
  2. Replies: 0
    Last Post: 02-15-2018, 01:50 PM
  3. Replies: 2
    Last Post: 08-25-2017, 03:46 AM
  4. [SOLVED] Error Checking Macro to cycle through rows looking at specific columns for things
    By Hyflex in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 08-21-2015, 08:36 PM
  5. [SOLVED] I need a macro to cycle down in a column and add the row value to a specific cell
    By rjackson104 in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 07-02-2013, 12:28 PM
  6. Change date format of a specific Cell?
    By nbaj2k in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 08-24-2006, 07:02 PM
  7. [SOLVED] Run a macro on a fixed date cycle
    By Steve in forum Excel General
    Replies: 2
    Last Post: 04-28-2005, 09:06 AM

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