+ Reply to Thread
Results 1 to 4 of 4

Adjust Large Number of Cells for Daylight Saving Time

Hybrid View

  1. #1
    Registered User
    Join Date
    04-18-2009
    Location
    London, England
    MS-Off Ver
    Excel 2007
    Posts
    40

    Adjust Large Number of Cells for Daylight Saving Time

    Hello,

    I have been scratching my head a bit for on this one and checked the forum, but can't seem to come up with a solution at the moment.

    Currently I have a large quantity of data in cells spread over various worksheets that are currently daylight saving time adjusted and I'd like to change that so that they aren't.

    I'd like to have a macro that asks me what the daylight saving times and dates are, and if the cell contains a date that falls within this period, to subtract one hour from the time.

    The data in the workbook starts in worksheet 2 onwards (sheet one is like a coversheet), also the number of worksheets within the workbook is variable, as is the number of rows containing data within each workbook. Incidentally, the data in the workbooks always starts in cell A5.

    I have included a sample of one of the workbooks and would be most grateful for your thoughts and / or suggestions.

    Many Thanks in advance,
    twills
    Attached Files Attached Files

  2. #2
    Forum Expert davegugg's Avatar
    Join Date
    12-18-2008
    Location
    WI, US
    MS-Off Ver
    2010
    Posts
    1,884

    Re: Adjusting Large Number of Cells for Daylight Saving Time

    Are the dates that you are wanting to change always going to be only in column A?

    So basically:

    For sheets 2 through last sheet
    for column A rows 5 to last row
    if date is in daylight savings, subtract 1 hour

    Is that a correct summary?
    Is your code running too slowly?
    Does your workbook or database have a bunch of duplicate pieces of data?
    Have a look at this article to learn the best ways to set up your projects.
    It will save both time and effort in the long run!


    Dave

  3. #3
    Registered User
    Join Date
    04-18-2009
    Location
    London, England
    MS-Off Ver
    Excel 2007
    Posts
    40

    Re: Adjusting Large Number of Cells for Daylight Saving Time

    Dave,

    Yes, that's exactly spot on.

    twills

  4. #4
    Forum Expert davegugg's Avatar
    Join Date
    12-18-2008
    Location
    WI, US
    MS-Off Ver
    2010
    Posts
    1,884

    Re: Adjust Large Number of Cells for Daylight Saving Time

    How's this work for you?

    Public Sub twills()
    
    Dim lngLastRow As Long
    Dim StartDaylight As Date
    Dim EndDaylight As Date
    
    StartDaylight = CDate(InputBox("Enter the date of daylight savings start.", "Daylight Savings Start Date"))
    EndDaylight = CDate(InputBox("Enter the date of daylight savings end.", "Daylight Savings End Date"))
    
    For i = 2 To Sheets.Count
        lngLastRow = Sheets(i).Cells(Rows.Count, 1).End(xlUp).Row
        For j = 5 To lngLastRow
            If Sheets(i).Cells(j, 1).Value >= StartDaylight Then
                If Sheets(i).Cells(j, 1).Value <= EndDaylight Then
                    Sheets(i).Cells(j, 1).Value = Sheets(i).Cells(j, 1).Value - 1 / 24
                End If
            End If
        Next j
    Next i
    
    End Sub

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Tags for this Thread

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