+ Reply to Thread
Results 1 to 5 of 5

VBA Script keeps Changing my Formula when it runs!!

  1. #1
    Registered User
    Join Date
    03-29-2023
    Location
    Florida
    MS-Off Ver
    Office Pro 2013
    Posts
    3

    VBA Script keeps Changing my Formula when it runs!!

    I created a VBA Script to run a conditional formatting on a sheet to highlight name matches.
    Each time the script is ran the one part of the formula gets changed, coincidentally and maybe related, the number it changes to is one more than the color code.

    Here is part of my script and the formula.

    Selection.FormatConditions.Add Type:=xlExpression, Formula1:= _
    "=COUNTIF($J$1:$J$108,$A1)>0"
    Selection.FormatConditions(Selection.FormatConditions.Count).SetFirstPriority
    With Selection.FormatConditions(1).Interior
    .PatternColorIndex = xlAutomatic
    .Color = 65535
    .TintAndShade = 0

    The formulac keeps changing to

    "=COUNTIF($J$1:$J$108,$A65536)>0"

    and highlighting the cell below the one it should be.


    Any help or guidance would be greatly appreciated.

  2. #2
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: VBA Script keeps Changing my Formula when it runs!!

    Can you post the rest of the code and details of the range/logic of the conditional formatting you are trying to apply?
    If posting code please use code tags, see here.

  3. #3
    Registered User
    Join Date
    03-29-2023
    Location
    Florida
    MS-Off Ver
    Office Pro 2013
    Posts
    3

    Re: VBA Script keeps Changing my Formula when it runs!!

    Sub MatchNames()
    ActiveWindow.SmallScroll Down:=75
    Range("J2:J108,A1:A1000").Select
    Range("A1").Activate
    Selection.FormatConditions.Add Type:=xlExpression, Formula1:= _
    "=COUNTIF($J$1:$J$108,$A1)>0"
    Selection.FormatConditions(Selection.FormatConditions.Count).SetFirstPriority
    With Selection.FormatConditions(1).Interior
    .PatternColorIndex = xlAutomatic
    .Color = 65535
    .TintAndShade = 0
    End With
    Selection.FormatConditions(1).StopIfTrue = True
    ActiveWindow.LargeScroll Down:=-22
    ActiveWindow.SmallScroll Down:=102
    ActiveWindow.ScrollRow = 129
    ActiveWindow.ScrollRow = 128
    ActiveWindow.ScrollRow = 127
    ActiveWindow.ScrollRow = 126
    ActiveWindow.ScrollRow = 125
    ActiveWindow.ScrollRow = 123
    ActiveWindow.ScrollRow = 122
    ActiveWindow.ScrollRow = 120
    ActiveWindow.ScrollRow = 118
    ActiveWindow.ScrollRow = 114
    ActiveWindow.ScrollRow = 110
    ActiveWindow.ScrollRow = 107
    ActiveWindow.ScrollRow = 104
    ActiveWindow.ScrollRow = 99
    ActiveWindow.ScrollRow = 95
    ActiveWindow.ScrollRow = 91
    ActiveWindow.ScrollRow = 87
    ActiveWindow.ScrollRow = 84
    ActiveWindow.ScrollRow = 80
    ActiveWindow.ScrollRow = 77
    ActiveWindow.ScrollRow = 74
    ActiveWindow.ScrollRow = 70
    ActiveWindow.ScrollRow = 67
    ActiveWindow.ScrollRow = 65
    ActiveWindow.ScrollRow = 60
    ActiveWindow.ScrollRow = 58
    ActiveWindow.ScrollRow = 55
    ActiveWindow.ScrollRow = 53
    ActiveWindow.ScrollRow = 51
    ActiveWindow.ScrollRow = 48
    ActiveWindow.ScrollRow = 46
    ActiveWindow.ScrollRow = 43
    ActiveWindow.ScrollRow = 40
    ActiveWindow.ScrollRow = 38
    ActiveWindow.ScrollRow = 34
    ActiveWindow.ScrollRow = 32
    ActiveWindow.ScrollRow = 31
    ActiveWindow.ScrollRow = 30
    ActiveWindow.ScrollRow = 28
    ActiveWindow.ScrollRow = 26
    ActiveWindow.ScrollRow = 25
    ActiveWindow.ScrollRow = 24
    ActiveWindow.ScrollRow = 23
    ActiveWindow.ScrollRow = 22
    ActiveWindow.ScrollRow = 20
    ActiveWindow.ScrollRow = 19
    ActiveWindow.ScrollRow = 18
    ActiveWindow.ScrollRow = 17
    ActiveWindow.ScrollRow = 16
    ActiveWindow.ScrollRow = 15
    ActiveWindow.ScrollRow = 14
    ActiveWindow.ScrollRow = 13
    ActiveWindow.ScrollRow = 12
    ActiveWindow.ScrollRow = 11
    ActiveWindow.ScrollRow = 10
    ActiveWindow.ScrollRow = 9
    ActiveWindow.ScrollRow = 8
    ActiveWindow.ScrollRow = 7
    ActiveWindow.ScrollRow = 5
    ActiveWindow.ScrollRow = 4
    ActiveWindow.ScrollRow = 3
    ActiveWindow.ScrollRow = 2
    ActiveWindow.ScrollRow = 1
    End Sub

  4. #4
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: VBA Script keeps Changing my Formula when it runs!!

    Which range do you want to apply the conditional formatting to?

  5. #5
    Registered User
    Join Date
    03-29-2023
    Location
    Florida
    MS-Off Ver
    Office Pro 2013
    Posts
    3
    Quote Originally Posted by Norie View Post
    Which range do you want to apply the conditional formatting to?
    The A1:A1000 range. Thanks for the reply!!

+ 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. Close file after VBA script runs command
    By wherdzik in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 08-17-2020, 12:11 PM
  2. Changing Formula to a VBA script
    By randy2012 in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 01-12-2018, 07:27 AM
  3. [SOLVED] My formula runs slow when changing it.
    By Dark0Prince in forum Excel General
    Replies: 8
    Last Post: 01-12-2017, 01:44 PM
  4. Script runs on other workbooks
    By CKlapperich in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 08-04-2014, 04:05 PM
  5. If then statement to control when the script runs
    By realniceguy5000 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 04-29-2009, 06:42 PM
  6. Mouse Focus Changes After Script Runs
    By ClivePoole in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 12-12-2008, 02:45 AM
  7. Script that edits the text printed on the button that runs the script
    By petalred in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 11-18-2008, 02:41 PM

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