+ Reply to Thread
Results 1 to 6 of 6

Repeat the macro every 15 sec after opening the excel file

  1. #1
    Registered User
    Join Date
    04-28-2022
    Location
    belgium
    MS-Off Ver
    2022
    Posts
    3

    Smile Repeat the macro every 15 sec after opening the excel file

    Hello evryone,

    I would like to have a duplicate checks on a column ( C column in my case) repeating itself every 15 seconds at the opening of the excel file or each time the user add a data into the column ( C column after the opening )

    I know that for the macro to start executing at the opening, I have to put it in " This workbook" MEO.

    The timer can be done with sth like this application.OnTime When:=Now + TimeValue("0:" + "0" + "30")

    For the repeating part, I read that I could use a GoTo or do an infinite loop

    The Macro that I would like to repeated is a duplicate check in the columns
    - If duplicate, the rows should be highlighted in red.
    - If the duplicate is removed, the rows should not be highlighted anymore.

    Sub dupli_check()

    Dim xMin As String

    repeat:

    Dim LastRow As Long

    ActiveSheet.Select

    LastRow = ActiveSheet.UsedRange.Rows.Count

    For r = 6 To LastRow

    If WorksheetFunction.CountIf(Range("C6:C" & LastRow), Cells(r, 3).Value) > 1 And Cells(r, 3).Value <> "" Then
    Rows(r).Interior.ColorIndex = 3

    ElseIf WorksheetFunction.CountIf(Range("C7:C" & LastRow), Cells(r, 3).Value) < 1 Or Cells(r, 3).Value = "" Then
    Rows(r).Interior.ColorIndex = 2

    Next r

    Else

    Application.OnTime Now() + TimeValue("0:" + "0" + "30"), "repeat"

    GoTo repeat

    End Sub
    I'm a bit lost. Could you help me figure where is my error ? Thanks you for you time and help

    Br,
    Martin
    Attached Files Attached Files

  2. #2
    Forum Expert CheeseSandwich's Avatar
    Join Date
    12-22-2021
    Location
    Kent, England
    MS-Off Ver
    365 - 2503
    Posts
    1,485

    Re: Repeat the macro every 15 sec after opening the excel file

    You could use conditional formatting to highlight duplicates - it will be live all the time the workbook is open?

    I would say that having code fire every 15 seconds will make using the spreadsheet rather annoying.
    If things don't change they stay the same

  3. #3
    Registered User
    Join Date
    04-28-2022
    Location
    belgium
    MS-Off Ver
    2022
    Posts
    3

    Re: Repeat the macro every 15 sec after opening the excel file

    Hi CheeseSandwich,

    For now I'm using condtionnal formatting but I have to use 2 rules. If I only use one, the rows that are empty in my selection are also highlighted in red because empty rows are duplicates.

    So I have 2 rules "fighting" each other.

    First is the one to highlight in red rows that contain a duplicate
    2 snd is the one putting in blanck rows that don't have data in that cell

    With that, each time I add data in this colum ( C column) I have a small delay.

    Also I would like this conditionnal formatting to be applied at several sheets.

  4. #4
    Forum Expert CheeseSandwich's Avatar
    Join Date
    12-22-2021
    Location
    Kent, England
    MS-Off Ver
    365 - 2503
    Posts
    1,485

    Re: Repeat the macro every 15 sec after opening the excel file

    So if I was looking for duplicates and wanted to ignore blanks I might use a formula in the conditional formatting box like:
    Formula: copy to clipboard
    Please Login or Register  to view this content.

    I would then apply that conditional formatting to the whole of column A in the above example.

    Try it, select column A and add CF and use the formula above and then put some duplicates into column A

  5. #5
    Forum Expert CheeseSandwich's Avatar
    Join Date
    12-22-2021
    Location
    Kent, England
    MS-Off Ver
    365 - 2503
    Posts
    1,485

    Re: Repeat the macro every 15 sec after opening the excel file

    You can also extend the range to be highlighted, see attached.
    Attached Files Attached Files

  6. #6
    Registered User
    Join Date
    04-28-2022
    Location
    belgium
    MS-Off Ver
    2022
    Posts
    3

    Re: Repeat the macro every 15 sec after opening the excel file

    It would work if the column I'm checking is only data. In my case, the column i'm checking is a formula concatenating the data of 2 columns. But you showed the way. I will use a second column that I will hide and having this formula ( IF(A1<>"",COUNTIFS($A$1:$A$10000,$A6),VALUE(1)).

    My MFC will be on that last column having a basic formula $A1>1

    Thanks for your help I still be working on the macro without you

+ 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] Run macro on opening of any excel file
    By koticphreak in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 02-27-2020, 05:19 PM
  2. [SOLVED] Macro to open Excel file, run other macros save, and close file & repeat.
    By Ronnet2 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 11-08-2015, 09:47 AM
  3. Getting Macro are disabled message when opening my excel file?
    By RustyNail in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 04-15-2015, 01:16 PM
  4. Macro to delete excel file on opening
    By dantray02 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 11-03-2014, 01:11 PM
  5. Activate VB Macro when opening excel file
    By rizmomin in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 02-21-2012, 01:35 PM
  6. Macro/VBA needed for opening excel file
    By tcw1986 in forum Excel Programming / VBA / Macros
    Replies: 35
    Last Post: 01-16-2012, 05:08 AM
  7. Macro available when opening new excel file
    By skrimpy in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 03-19-2005, 08:07 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