Consulting

Results 1 to 2 of 2

Thread: How do I fix this VBA Code?

  1. #1

    How do I fix this VBA Code?

    Dim i As Integer
    i = 20
    Do While i <= 2215
        Range("Z3:Z19").Select
        Range(Selection, Selection.End(xlDown)).Select
        ActiveWindow.SmallScroll Down:=6Selection.FormatConditions.Add Type:=xlCellValue, Operator:=xlEqual, _
        Formula1:="='Look up Tables'!Zi"
        Selection.FormatConditions(Selection.FormatConditions.Count).SetFirstPriority
        With Selection.FormatConditions(1).Font
            .Color = -16383844
            .TintAndShade = 0
        End With
        With Selection.FormatConditions(1).Interior
            .PatternColorIndex = xlAutomatic
            .Color = 13551615
            .TintAndShade = 0
        End With
        Selection.FormatConditions(1).StopIfTrue = False
        i = i + 1
    Loop
    I know it's wrong, but I don't understand how something like this wouldn't work. Also, how would I get it to work and still do the same thing?
    Last edited by Aussiebear; 04-26-2023 at 12:13 PM. Reason: Adjusted the code tags

  2. #2
    VBAX Sage
    Joined
    Apr 2007
    Location
    United States
    Posts
    8,727
    Location
    1. I added CODE tags to your macro -- you can use the [#] incon next time to add them

    2. No need to .Select or .Scroll - you can work directly on objects

    3. This part 'looks wrong'

    Formula1:="='Look up Tables'!Zi"

    If I always = 20 then try

    Formula1:="='Look up Tables'!Z20"
    


    If not, then try

    Formula1:="='Look up Tables'!Z" & i
    


    Otherwise attach a workbook with the WHOLE macro and details
    ---------------------------------------------------------------------------------------------------------------------

    Paul


    Remember: Tell us WHAT you want to do, not HOW you think you want to do it

    1. Use [CODE] ....[/CODE ] Tags for readability
    [CODE]PasteYourCodeHere[/CODE ] -- (or paste your code, select it, click [#] button)
    2. Upload an example
    Go Advanced / Attachments - Manage Attachments / Add Files / Select Files / Select the file(s) / Upload Files / Done
    3. Mark the thread as [Solved] when you have an answer
    Thread Tools (on the top right corner, above the first message)
    4. Read the Forum FAQ, especially the part about cross-posting in other forums
    http://www.vbaexpress.com/forum/faq...._new_faq_item3

Posting Permissions

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