0

I get a error that no cells are found and it highlights

Range("A6:A109").SpecialCells(xlCellTypeVisible).Find("Temp").Select

When I open the file it looks like this below and column F is hidden and that's where my value is.

enter image description here

How and where can I add a code where it unhides everything? Also, when there is no value it also bugs and Im not sure what to add to prevent that

Sub HrsInput()

' Disable screen updating.

    Application.ScreenUpdating = False
    Application.DisplayAlerts = False
    
' Dim workbooks and sheet names.

    Dim WB1, WB2 As Workbook, Year As String
    Set WB1 = ActiveWorkbook
    Year = Mid(ActiveSheet.Name, 10, 4)
      
' Copy-n-paste raw reports.

    Dim FSO As Object, SourcePath As String, DestinPath As String
    Set FSO = CreateObject("Scripting.FileSystemObject")
    SourcePath = "\\ONTWSFS003\share\MIRALOMA\Brian\Raw Reports (FM)\*.xls"
    DestinPath = "\\ONTWSFS003\share\MIRALOMA\Brian\"
    FSO.CopyFile SourcePath, DestinPath

' Repeat below process until encountering an error.

    Dim FileCount As Integer
    
    Filename = Dir(SourcePath)
    Do While Filename <> ""
        FileCount = FileCount + 1
        Filename = Dir()
    Loop
        
    For FileNum = 1 To FileCount
    
    ' Open raw report.
    
        Workbooks.Open Filename:= _
            "\\ONTWSFS003\share\MIRALOMA\Brian\*.xls"
    
    ' Capture raw report and total hours.
    
        Set WB2 = ActiveWorkbook
        Dim TotalOT As Double, BUNum As String, ReportDate() As String, WeekNum As Integer, ColNum As Integer
        
        BUNum = Left(Range("A5"), 7)
        ReportDate = Split(Range("A7"), " ")
        WeekNum = WorksheetFunction.WeekNum(ReportDate(4))
        
        Range("A:Q").UnMerge
        
        ' If not OT then skip the file.
        
        If Not Range("A14:Z14").Find("OT1.5") Is Nothing Then
            Range("A14:Z14").Find("OT1.5").Select
            ColNum = Selection.Column
            
            Range("A15:A300").Find("total").Select
            Selection.Offset(0, ColNum - 1).Select
            TotalOT = Selection.Value
               
        ' Fill out job title if empty.
        
            Dim EmptyJobRng As Range, EmptyJobCell As Range
            Set EmptyJobRng = Range("C15:C150").SpecialCells(xlCellTypeBlanks)
            For Each EmptyJobCell In EmptyJobRng.Cells
                If EmptyJobCell.Offset(0, 2) <> "" Then
                    EmptyJobCell = EmptyJobCell.Offset(-1, 0)
                End If
            Next EmptyJobCell
        
        ' Filter by temp only.
        
            If Not Range("C15:C100").Find("*") Is Nothing Then
                With Range("C14:Y150")
                    .AutoFilter field:=3, Criteria1:="<>"
                    .AutoFilter field:=1, Criteria1:="*Temp"
                End With
            End If
                
        ' Calculate total temp OT hours.
        
            Dim TotalTempOT As Double, OT As Range
            TotalTempOT = 0
            Range("A14:Z14").Find("OT1.5").Select
            Selection.Offset(1, 0).Select
            Selection.Resize(150, 1).Select
            Set OT = Selection.SpecialCells(xlCellTypeVisible)
            For Each TempOT In OT.Cells
                TotalTempOT = TotalTempOT + TempOT
            Next TempOT
            
        ' Filter by BU and blank rows.
        
            WB1.Activate
            With Range("A5:BD30")
                .AutoFilter field:=2, Criteria1:=BUNum
                .AutoFilter field:=WeekNum + 2, Criteria1:="="
            End With
        
        ' Locate temp row and week column to paste total temp OT hours.
        
            Range("A6:A109").SpecialCells(xlCellTypeVisible).Find("Temp").Select
            Selection.Offset(0, WeekNum + 1).Select
            Selection = TotalTempOT
            
        ' Locate CEVA row and week column to paste total CEVA OT hours (total OT - total temp OT).
        
            Range("A6:A109").SpecialCells(xlCellTypeVisible).Find("CEVA").Select
            Selection.Offset(0, WeekNum + 1).Select
            Selection = TotalOT - TotalTempOT
              
        ' Clear filters.
        
            Sheets("Tracking " & Year & " (by BU)").ShowAllData
            
        End If
    
    ' Delete current raw report.
    
        WB2.Activate
        ActiveWorkbook.Saved = True
        ActiveWorkbook.ChangeFileAccess xlReadOnly
        Kill ActiveWorkbook.FullName
        WB2.Close
        WB1.Activate

    Next FileNum
    
' Update week number and weekly total OT hours.

    ' Week number
    Range("A4").Offset(0, WeekNum).Select
    Selection.Copy
    Selection.Offset(0, 1).Select
    Selection.PasteSpecial (xlPasteFormulas)
    
    ' Report date
    Range("A5").Offset(0, WeekNum + 1).Select
    Selection = "WE" & ReportDate(4)
    
    ' Weekly total OT hours
    Range("A110").Offset(0, WeekNum).Select
    Selection.Copy
    Selection.Offset(0, 1).Select
    Selection.PasteSpecial (xlPasteFormulas)
    
    ' Format Painter to new column
    Range("B:B").Select
    Selection.Offset(0, WeekNum - 1).Select
    Selection.Copy
    Selection.Offset(0, 1).Select
    Selection.PasteSpecial (xlPasteFormats)
    
    Sheets("Tracking " & Year & " (by Loc)").Select
    Range("A:A").Select
    Selection.Offset(0, WeekNum - 1).Select
    Selection.Copy
    Selection.Offset(0, 1).Select
    Selection.PasteSpecial (xlPasteFormats)

' Notification when complete.

    MsgBox "Data imported successfully.", vbOKOnly, "Complete"
    
' Enable screen updating.

    Application.ScreenUpdating = True
    Application.DisplayAlerts = True

End Sub
braX
  • 11,506
  • 5
  • 20
  • 33
Kim
  • 31
  • 5
  • Something like `Cells.EntireColumn.Hidden = False`, making sure to specify the workbook/worksheet the cells are in/on. – BigBen May 23 '22 at 19:26
  • I added the code Cells.EntireColumn.Hidden = False before it debugs and it didn't unhide the columns – Kim May 23 '22 at 19:38
  • Using simple words, in a few sentences, kindly explain what the code is supposed to do. Also, provide additional screenshots of the before and the after. BTW, you cannot unhide rows in a filtered range using the `Range.Hidden` property. – VBasic2008 May 23 '22 at 20:07
  • This exact same "no cells found" error was already addressed in your earlier post: https://stackoverflow.com/questions/72309713/vba-no-cells-are-found Plus, when using `Find()` the robust approach is to check the return value is not `Nothing` so you know what to do next. – Tim Williams May 23 '22 at 20:16
  • 2
    Does this answer your question? [VBA No Cells are found](https://stackoverflow.com/questions/72309713/vba-no-cells-are-found) – Solar Mike May 23 '22 at 20:24

0 Answers0