+ Reply to Thread
Results 1 to 2 of 2

VBA Conditional Formatting Issue

Hybrid View

  1. #1
    Registered User
    Join Date
    06-30-2008
    Location
    Georgia
    MS-Off Ver
    2013
    Posts
    72

    Question VBA Conditional Formatting Issue

    I am having issues setting conditional formatting via VBA. I am setting it this was since when the code deletes my rows the formatting is deleted as well. The problem I have is, it does not properly set the formatting. It should be setting at follows but it mixing the two together in a sense.

    Border:
    • If A5 is not blank it should add cell borders through T to the bottom of the entire workbook.

    Gray Fill:
    • If A5 is not blank it should fill column Q & R to the bottom of the entire workbook.

    It is difficult to provide a sample workbook, but if required I will do my best to get a mock up.

    My current code is as follows:
    Option Explicit
    
    Public Sub LoadEffort()
    
    '//||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||\\'
    '||   Open all Excel files in a specific folder and combines data into one sheet                               ||'
    '||   John_w (10/8/2010 )     (2007-2010 compatible)                                                           ||'
    '||   http://www.mrexcel.com/forum/excel-questions/500421-macro-merge-multiple-files-into-one-worksheet.html   ||'
    '\\||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||//'
    
        Dim path As String
        Dim shtDest As Worksheet
        Dim Wkb As Workbook
        Dim CopyRng As Range, Dest As Range
        Dim RowofCopySheet As Integer
        Dim selectedFiles As Variant, filename As Variant
        Dim i As Long
        Dim LR As Long
        Dim rngFilter As Range
        Dim r As Long, f As Long
        Dim GetDesktop As String
                
        Application.ScreenUpdating = False
        Application.Calculation = xlManual
            
    '// Deletes the Effort Dump sheet data to prepare for new report being imported.\\'
    
            Sheets("Effort Dump").Activate
            Set rngFilter = ActiveSheet.AutoFilter.Range
            r = rngFilter.Rows.Count
            f = rngFilter.SpecialCells(xlCellTypeVisible).Count
            If r > f Then
            ActiveWorkbook.Worksheets("Effort Dump").AutoFilter.Sort.SortFields.Clear
            ActiveSheet.ShowAllData
            End If
            i = Range("A" & Rows.Count).End(xlUp).Row + 3
            If i = 4 Then
                Range("A5").Select
            Else
                Rows("5:5").Select
                Range(Selection, Selection.End(xlDown)).Select
                Range(Selection, Selection.End(xlDown)).Select
                Selection.Delete
                With Sheet11
                    With Sheet11.Range("A:T")
                        .FormatConditions.Delete
                    End With
                    With .Range("$A$5:$T$1048576")
                        .Activate
                        .FormatConditions.Add xlExpression, Formula1:="=NOT(ISBLANK($A5))"
                        .FormatConditions(1).Borders.LineStyle = xlContinuous
                        .FormatConditions(1).Borders.Weight = xlThin
                    End With
                    With .Range("$Q$5:$R$1048576")
                        .Activate
                        .FormatConditions.Add xlExpression, Formula1:="=NOT(ISBLANK($A5))"
                        .FormatConditions(1).Interior.ColorIndex = 48
                    End With
                End With
                Range("A5").Select
            End If
            Set shtDest = ActiveWorkbook.Sheets("Effort Dump")
    
    '// Importing of the new files.\\'
                    
        RowofCopySheet = 2 ' Row to start on in the sheets you are copying from
        GetDesktop = CreateObject("WScript.Shell").SpecialFolders("Desktop") & _
            Application.PathSeparator
    
        path = GetDesktop
        
        selectedFiles = SelectFiles(path)
    
        If IsArray(selectedFiles) Then
        
            Application.EnableEvents = False
            
    '// Open and merge each selected file
            
            For Each filename In selectedFiles
                If filename <> ActiveWorkbook.FullName Then
                    Set Wkb = Workbooks.Open(filename)
                    With Wkb.Sheets(1)
                        Set CopyRng = .Range(.Cells(RowofCopySheet, 1), _
                            .Cells(Cells(Rows.Count, 1).End(xlUp).Row, .Cells(1, Columns.Count).End(xlToLeft).Column))
                    End With
                    Set Dest = shtDest.Range("A" & shtDest.UsedRange.SpecialCells(xlCellTypeLastCell).Row + 1)
                    CopyRng.Copy
                    Dest.PasteSpecial xlPasteValuesAndNumberFormats
                    Application.CutCopyMode = False 'Clear Clipboard
                    Wkb.Close False
                End If
            Next
        
            Application.EnableEvents = True
    
        Range("A1").Select
        
        MsgBox "Processing Complete."
        
        Else
        
            MsgBox "No files were selected"
        
        End If
        
        Application.ScreenUpdating = True
        
        Application.Calculation = xlAutomatic
        
    End Sub
    
    Private Function SelectFiles(startFolderPath As String) As Variant
    
        Dim Filter As String
        Dim FilterIndex As Integer
        
        'File filters
        Filter = "Excel workbooks (*.xls), *.xls"
        FilterIndex = 1
        
        'Set start drive and path
        ChDrive (startFolderPath)
        ChDir (startFolderPath)
        
        With Application
            'Get array of selected file(s)
            SelectFiles = .GetOpenFilename(Filter, FilterIndex, "Select File(s) to Merge", , MultiSelect:=True)
            
            'Reset start drive and path
            ChDrive (.DefaultFilePath)
            ChDir (.DefaultFilePath)
        End With
    
    End Function
    EDIT: I am using Excel 2013.
    Last edited by maddog9486; 05-06-2014 at 02:12 PM.

  2. #2
    Registered User
    Join Date
    06-30-2008
    Location
    Georgia
    MS-Off Ver
    2013
    Posts
    72

    Re: VBA Conditional Formatting Issue

    Anyone had a chance to take a look and see where I am going wrong? Thanks.

+ 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. Conditional Formatting Issue
    By Tailoredcs in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 06-11-2013, 02:29 PM
  2. Conditional Formatting Issue
    By bumperbg in forum Excel General
    Replies: 0
    Last Post: 07-06-2011, 04:19 AM
  3. Conditional Formatting Issue
    By netcat17 in forum Excel General
    Replies: 6
    Last Post: 04-05-2010, 07:57 PM
  4. Conditional Formatting Issue
    By RNiner in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 10-04-2008, 06:35 AM
  5. conditional formatting issue
    By QUESTION-MARK in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 04-19-2006, 08:10 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