+ Reply to Thread
Results 1 to 14 of 14

I am using scripting dictionary method -If no data - need a message box -

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    09-06-2011
    Location
    northern ireland
    MS-Off Ver
    Excel 365
    Posts
    180

    I am using scripting dictionary method -If no data - need a message box -

    
    Dim x, y(), i&, j&, k&, l&, s$
    x = Range("C1:I" & Cells(Rows.Count, 3).End(xlUp).Row).Value
    ReDim y(1 To UBound(x), 1 To 5)
    
    With CreateObject("Scripting.Dictionary")
        .CompareMode = 1
        For i = 1 To UBound(x)
                    If x(i, 4) = "Overtime" Or x(i, 4) = "Overtime On Saturday" Or x(i, 4) = "Overtime On Sunday" Or x(i, 4) = "Saturday Premium" Or x(i, 4) = "Sunday Premium" Or x(i, 4) = "Travel" Or x(i, 4) = "Travel Saturday" Or x(i, 4) = "Travel Sunday/Holiday" Then
                s = x(i, 2) & x(i, 4)    'BEMSID&HOURS_DESCR is the unique key
                'if key already exists in the dictionary, we sum AMOUNT
                If .exists(s) Then
                    k = .Item(s): y(k, 5) = y(k, 5) + x(i, 7)    'y(k, 5) is 'AMOUNT'
                Else 'if key not exists
                    j = j + 1: .Item(s) = j 'add key in the dictionary,
                    ' and fill the output array
                    y(j, 1) = x(i, 2): y(j, 2) = x(i, 1) 'column BEMSID
                    y(j, 2) = Split(x(i, 1), ",")(0)  'column EMPLOYEE, surname only
                    y(j, 3) = x(i, 4): y(j, 4) = x(i, 7) 'column HOURS_DESCR
                    y(j, 4) = "" 'column Value, 
                    y(j, 5) = x(i, 7)    'column AMOUNT (Units)
                End If
            End If
        Next i
    End With
    If j = 0 Then Exit Sub
    So this is my code as above, but what it there is nothing in the data when I open the file ? It doesn't do anything apart from open the data file to extract the info from so how can I put something in here to say if no results obtained then have a message box appear to say "no data to import this month" and to exit the sub....

    Many thanks in advance
    Leanne
    Last edited by leanne2011; 02-03-2012 at 04:48 AM.

  2. #2
    Forum Expert JapanDave's Avatar
    Join Date
    06-10-2008
    Location
    The grid, I got in!
    MS-Off Ver
    Excel 2010/13
    Posts
    1,696

    Re: I am using scripting dictionary method -If no data - need a message box -

    Hey,

    Try this,

    Dim x, y(), i&, j&, k&, l&, s$
    x = Range("C1:I" & Cells(Rows.Count, 3).End(xlUp).Row).Value
    ReDim y(1 To UBound(x), 1 To 5)
      On Error Goto ErrHandler
    With CreateObject("Scripting.Dictionary")
        .CompareMode = 1
        For i = 1 To UBound(x)
                    If x(i, 4) = "Overtime" Or x(i, 4) = "Overtime On Saturday" Or x(i, 4) = "Overtime On Sunday" Or x(i, 4) = "Saturday Premium" Or x(i, 4) = "Sunday Premium" Or x(i, 4) = "Travel" Or x(i, 4) = "Travel Saturday" Or x(i, 4) = "Travel Sunday/Holiday" Then
                s = x(i, 2) & x(i, 4)    'BEMSID&HOURS_DESCR is the unique key
                'if key already exists in the dictionary, we sum AMOUNT
                If .exists(s) Then
                    k = .Item(s): y(k, 5) = y(k, 5) + x(i, 7)    'y(k, 5) is 'AMOUNT'
                Else 'if key not exists
                    j = j + 1: .Item(s) = j 'add key in the dictionary,
                    ' and fill the output array
                    y(j, 1) = x(i, 2): y(j, 2) = x(i, 1) 'column BEMSID
                    y(j, 2) = Split(x(i, 1), ",")(0)  'column EMPLOYEE, surname only
                    y(j, 3) = x(i, 4): y(j, 4) = x(i, 7) 'column HOURS_DESCR
                    y(j, 4) = "" 'column Value, 
                    y(j, 5) = x(i, 7)    'column AMOUNT (Units)
                End If
            End If
        Next i
    End With
    If j = 0 Then Exit Sub
    ErrHandler:
                 MsgBox "No data to import this month"
    Exit Sub
    Be fore warned, I regularly post drunk. So don't take offence (too much) to what I say.
    I am the real 'Napster'
    The Grid. A digital frontier. I tried to picture clusters of information as they moved through the computer. What did they look like? Ships? motorcycles? Were the circuits like freeways? I kept dreaming of a world I thought I'd never see. And then, one day...

    If you receive help please give thanks. Click the * in the bottom left hand corner.

    snb's VBA Help Files

  3. #3
    Forum Contributor
    Join Date
    09-06-2011
    Location
    northern ireland
    MS-Off Ver
    Excel 365
    Posts
    180

    Re: I am using scripting dictionary method -If no data - need a message box -

    Thanks for the quick response - but I got it wrong. The code does not de bug but instead the data that I have called from a getopenfile name just remains open and does not finish the code the error handler wont work

  4. #4
    Forum Expert JapanDave's Avatar
    Join Date
    06-10-2008
    Location
    The grid, I got in!
    MS-Off Ver
    Excel 2010/13
    Posts
    1,696

    Re: I am using scripting dictionary method -If no data - need a message box -

    Can you post the whole code?

  5. #5
    Forum Contributor
    Join Date
    09-06-2011
    Location
    northern ireland
    MS-Off Ver
    Excel 365
    Posts
    180

    Re: I am using scripting dictionary method -If no data - need a message box -

    Hi - yes sure

    
    Option Explicit
    Dim Filesavename As String
    Dim WeeklyFN As String
    Dim MainFN As String
    Dim MFile As String
    Dim lrow As Long
    Dim sfield As String
    Dim cellcol As Long
    Dim i As Long
    Dim lastrow As Long
    Dim rownumber As Long
    Dim c As Object
    Dim iReply As String
    Dim iReply1 As String
    
    
    
    
    Sub SP()
    
    
    
    MFile = ActiveWorkbook.Name
    Application.ScreenUpdating = False
    proceed:
    WeeklyFN = Application.GetOpenFilename(fileFilter:="All files (*.*), *.*", Title:="Please open the GT Feed")
    If WeeklyFN = "" Then
        MsgBox "You have not selected a file."
        GoTo proceed
    Else
        Workbooks.Open Filename:=WeeklyFN
        WeeklyFN = ActiveWorkbook.Name
    End If
     Columns("D:D").Select
        Selection.TextToColumns Destination:=Range("D1"), DataType:=xlDelimited, _
            TextQualifier:=xlDoubleQuote, ConsecutiveDelimiter:=False, Tab:=True, _
            Semicolon:=False, Comma:=False, Space:=False, Other:=False, FieldInfo _
            :=Array(1, 1), TrailingMinusNumbers:=True
    
    'Workbooks.Open Filename:= _
            "N:\PAYROLL\Leanne\LM\GT FEED.xls"
       'get row count
        Range("A1").Select
        Selection.End(xlDown).Select
        rownumber = ActiveCell.Row
     Range("A1").Select
        Cells.Find(What:="BEMSID", After:=ActiveCell, LookIn:=xlFormulas, LookAt _
            :=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:= _
            False, SearchFormat:=False).Activate
        Range("D2").Select
        Range(Selection, Selection.End(xlDown)).Select
        
        Range("D2").Select
     
     Dim x, y(), i&, j&, k&, l&, s$
    'x is the original array with the data. It starts from column C to column I, the length of
    'the array - from row 1 to the last filled cell in column C
    x = Range("C1:I" & Cells(Rows.Count, 3).End(xlUp).Row).Value
    'y is the output array, '1 to 5' means that it contains 5 columns
    ReDim y(1 To UBound(x), 1 To 5)
    
    With CreateObject("Scripting.Dictionary")
        .CompareMode = 1
        For i = 1 To UBound(x)
            'if values in column H on the sheet = ...
            If x(i, 4) = "Overtime" Or x(i, 4) = "Overtime On Saturday" Or x(i, 4) = "Overtime On Sunday" Or x(i, 4) = "Saturday Premium" Or x(i, 4) = "Sunday Premium" Or x(i, 4) = "Travel" Or x(i, 4) = "Travel Saturday" Or x(i, 4) = "Travel Sunday/Holiday" Then
                s = x(i, 2) & x(i, 4)    'BEMSID&HOURS_DESCR is the unique key
                'if key already exists in the dictionary, we sum AMOUNT
                If .exists(s) Then
                    k = .Item(s): y(k, 5) = y(k, 5) + x(i, 7)    'y(k, 5) is 'AMOUNT'
                Else 'if key not exists
                    j = j + 1: .Item(s) = j 'add key in the dictionary,
                    ' and fill the output array
                    y(j, 1) = x(i, 2): y(j, 2) = x(i, 1) 'column BEMSID
                    y(j, 2) = Split(x(i, 1), ",")(0)  'column EMPLOYEE, surname only
                    y(j, 3) = x(i, 4): y(j, 4) = x(i, 7) 'column HOURS_DESCR
                    y(j, 4) = "" 'column Value, not clear-need column to be blank so ok
                    y(j, 5) = x(i, 7)    'column AMOUNT (Units)
                End If
            End If
        Next i
    End With
    If j = 0 Then Exit Sub
    ErrHandler:
                 MsgBox "No data to import this month"
    Exit Sub
                    
    Windows("LM.xlsm").Activate
    Sheet2.Activate
    'Workbooks.Open Filename:="N:\PAYROLL\Leanne\LM\FILE TO IMPORT.xlsx"
    'Workbooks.Open Filename:=ThisWorkbook.Path & "\FILE TO IMPORT.xlsx" 'or so, if all files are in same folder
    With Sheets(2)
        .UsedRange.ClearContents
        .Columns(1).NumberFormat = "@"
        .[a1:e1].Value = Array("BEMSID", "EMPLOYEE", "HOURS_DESCR", "AMOUNT", "UNITS")
        .[a2:e2].Resize(j).Value = y()
       
        
    End With
      
      Application.DisplayAlerts = False
    
        
        'sFileNames = Application.GetSaveAsFilename(fileFilter:="All files (*.*), *.*", Title:="Please save import template")
          'If sFileNames = "False" Then Exit Sub
    
        'get row count
        Range("A1").Select
        Selection.End(xlDown).Select
        rownumber = ActiveCell.Row
        
        Range("A1").Select
        
        Columns("A:E").Select
        ActiveWorkbook.Worksheets("Sheet2").Sort.SortFields.Clear
        ActiveWorkbook.Worksheets("Sheet2").Sort.SortFields.Add Key:=Range("C2:C90") _
            , SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
        With ActiveWorkbook.Worksheets("Sheet2").Sort
            .SetRange Range("A1:E" & rownumber)
            .Header = xlYes
            .MatchCase = False
            .Orientation = xlTopToBottom
            .SortMethod = xlPinYin
            .Apply
        End With
        Range("A1").Select
        Sheet1.Select
        
    
    
           Exit Sub
        
        Windows("LM.xlsm").Activate
        Sheet1.Select
       MsgBox (iReply = "Select 2nd Step of Macro Process")
        
    
    End Sub

  6. #6
    Forum Expert JapanDave's Avatar
    Join Date
    06-10-2008
    Location
    The grid, I got in!
    MS-Off Ver
    Excel 2010/13
    Posts
    1,696

    Re: I am using scripting dictionary method -If no data - need a message box -

    Try this,

    Option Explicit
    Dim Filesavename As String
    Dim WeeklyFN As String
    Dim MainFN As String
    Dim MFile As String
    Dim lrow As Long
    Dim sfield As String
    Dim cellcol As Long
    Dim i As Long
    Dim lastrow As Long
    Dim rownumber As Long
    Dim c As Object
    Dim iReply As String
    Dim iReply1 As String
    Dim cel As Range
    
    
    
    
    Sub SP()
    
    
    
    MFile = ActiveWorkbook.Name
    Application.ScreenUpdating = False
    proceed:
    WeeklyFN = Application.GetOpenFilename(fileFilter:="All files (*.*), *.*", Title:="Please open the GT Feed")
    If WeeklyFN = "" Then
        MsgBox "You have not selected a file."
        GoTo proceed
    Else
        Workbooks.Open Filename:=WeeklyFN
        WeeklyFN = ActiveWorkbook.Name
    End If
     Columns("D:D").Select
        Selection.TextToColumns Destination:=Range("D1"), DataType:=xlDelimited, _
            TextQualifier:=xlDoubleQuote, ConsecutiveDelimiter:=False, Tab:=True, _
            Semicolon:=False, Comma:=False, Space:=False, Other:=False, FieldInfo _
            :=Array(1, 1), TrailingMinusNumbers:=True
    
    'Workbooks.Open Filename:= _
            "N:\PAYROLL\Leanne\LM\GT FEED.xls"
       'get row count
        Range("A1").Select
        Selection.End(xlDown).Select
        rownumber = ActiveCell.Row
     Range("A1").Select
        Cells.Find(What:="BEMSID", After:=ActiveCell, LookIn:=xlFormulas, LookAt _
            :=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:= _
            False, SearchFormat:=False).Activate
            Set cel = Cells.Find(What:="BEMSID", After:=ActiveCell, LookIn:=xlFormulas, LookAt _
            :=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:= _
            False, SearchFormat:=False).Activate
             If cel = "" Then
               ActiveWorkbook.Close False
                GoTo nxt
             End If
            
        Range("D2").Select
        Range(Selection, Selection.End(xlDown)).Select
        
        Range("D2").Select
     
     Dim x, y(), i&, j&, k&, l&, s$
    'x is the original array with the data. It starts from column C to column I, the length of
    'the array - from row 1 to the last filled cell in column C
    x = Range("C1:I" & Cells(Rows.Count, 3).End(xlUp).Row).Value
    'y is the output array, '1 to 5' means that it contains 5 columns
    ReDim y(1 To UBound(x), 1 To 5)
    
    With CreateObject("Scripting.Dictionary")
        .CompareMode = 1
        For i = 1 To UBound(x)
            'if values in column H on the sheet = ...
            If x(i, 4) = "Overtime" Or x(i, 4) = "Overtime On Saturday" Or x(i, 4) = "Overtime On Sunday" Or x(i, 4) = "Saturday Premium" Or x(i, 4) = "Sunday Premium" Or x(i, 4) = "Travel" Or x(i, 4) = "Travel Saturday" Or x(i, 4) = "Travel Sunday/Holiday" Then
                s = x(i, 2) & x(i, 4)    'BEMSID&HOURS_DESCR is the unique key
                'if key already exists in the dictionary, we sum AMOUNT
                If .exists(s) Then
                    k = .Item(s): y(k, 5) = y(k, 5) + x(i, 7)    'y(k, 5) is 'AMOUNT'
                Else 'if key not exists
                    j = j + 1: .Item(s) = j 'add key in the dictionary,
                    ' and fill the output array
                    y(j, 1) = x(i, 2): y(j, 2) = x(i, 1) 'column BEMSID
                    y(j, 2) = Split(x(i, 1), ",")(0)  'column EMPLOYEE, surname only
                    y(j, 3) = x(i, 4): y(j, 4) = x(i, 7) 'column HOURS_DESCR
                    y(j, 4) = "" 'column Value, not clear-need column to be blank so ok
                    y(j, 5) = x(i, 7)    'column AMOUNT (Units)
                End If
            End If
        Next i
    End With
    If j = 0 Then Exit Sub
    ErrHandler:
                 MsgBox "No data to import this month"
    Exit Sub
                    
    Windows("LM.xlsm").Activate
    Sheet2.Activate
    'Workbooks.Open Filename:="N:\PAYROLL\Leanne\LM\FILE TO IMPORT.xlsx"
    'Workbooks.Open Filename:=ThisWorkbook.Path & "\FILE TO IMPORT.xlsx" 'or so, if all files are in same folder
    With Sheets(2)
        .UsedRange.ClearContents
        .Columns(1).NumberFormat = "@"
        .[a1:e1].Value = Array("BEMSID", "EMPLOYEE", "HOURS_DESCR", "AMOUNT", "UNITS")
        .[a2:e2].Resize(j).Value = y()
       
        
    End With
      
      Application.DisplayAlerts = False
    
        
        'sFileNames = Application.GetSaveAsFilename(fileFilter:="All files (*.*), *.*", Title:="Please save import template")
          'If sFileNames = "False" Then Exit Sub
    
        'get row count
        Range("A1").Select
        Selection.End(xlDown).Select
        rownumber = ActiveCell.Row
        
        Range("A1").Select
        
        Columns("A:E").Select
        ActiveWorkbook.Worksheets("Sheet2").Sort.SortFields.Clear
        ActiveWorkbook.Worksheets("Sheet2").Sort.SortFields.Add Key:=Range("C2:C90") _
            , SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
        With ActiveWorkbook.Worksheets("Sheet2").Sort
            .SetRange Range("A1:E" & rownumber)
            .Header = xlYes
            .MatchCase = False
            .Orientation = xlTopToBottom
            .SortMethod = xlPinYin
            .Apply
        End With
        Range("A1").Select
        Sheet1.Select
        
    
    
           Exit Sub
        
        Windows("LM.xlsm").Activate
        Sheet1.Select
       MsgBox (iReply = "Select 2nd Step of Macro Process")
    nxt:
      MsgBox "No data was found"
    End Sub

  7. #7
    Forum Contributor
    Join Date
    09-06-2011
    Location
    northern ireland
    MS-Off Ver
    Excel 365
    Posts
    180

    Re: I am using scripting dictionary method -If no data - need a message box -

    Hi

    I just tried it - I get a run time error 424 ? at this point


    
    Set cel = Cells.Find(What:="BEMSID", After:=ActiveCell, LookIn:=xlFormulas, LookAt _
            :=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:= _
            False, SearchFormat:=False).Activate















    any ideas

  8. #8
    Forum Expert JapanDave's Avatar
    Join Date
    06-10-2008
    Location
    The grid, I got in!
    MS-Off Ver
    Excel 2010/13
    Posts
    1,696

    Re: I am using scripting dictionary method -If no data - need a message box -

    Try This,

    Option Explicit
    Dim Filesavename As String
    Dim WeeklyFN As String
    Dim MainFN As String
    Dim MFile As String
    Dim lrow As Long
    Dim sfield As String
    Dim cellcol As Long
    Dim i As Long
    Dim lastrow As Long
    Dim rownumber As Long
    Dim c As Object
    Dim iReply As String
    Dim iReply1 As String
    Dim cel As Variant
    
    
    
    
    Sub SP()
    
    
    
    MFile = ActiveWorkbook.Name
    Application.ScreenUpdating = False
    proceed:
    WeeklyFN = Application.GetOpenFilename(fileFilter:="All files (*.*), *.*", Title:="Please open the GT Feed")
    If WeeklyFN = "" Then
        MsgBox "You have not selected a file."
        GoTo proceed
    Else
        Workbooks.Open Filename:=WeeklyFN
        WeeklyFN = ActiveWorkbook.Name
    End If
     Columns("D:D").Select
        Selection.TextToColumns Destination:=Range("D1"), DataType:=xlDelimited, _
            TextQualifier:=xlDoubleQuote, ConsecutiveDelimiter:=False, Tab:=True, _
            Semicolon:=False, Comma:=False, Space:=False, Other:=False, FieldInfo _
            :=Array(1, 1), TrailingMinusNumbers:=True
    
    'Workbooks.Open Filename:= _
            "N:\PAYROLL\Leanne\LM\GT FEED.xls"
       'get row count
        Range("A1").Select
        Selection.End(xlDown).Select
        rownumber = ActiveCell.Row
     Range("A1").Select
        Cells.Find(What:="BEMSID", After:=ActiveCell, LookIn:=xlFormulas, LookAt _
            :=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:= _
            False, SearchFormat:=False).Activate
            cel = Cells.Find(What:="BEMSID", After:=ActiveCell, LookIn:=xlFormulas, LookAt _
            :=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:= _
            False, SearchFormat:=False).Activate
             If cel = "" Then
               ActiveWorkbook.Close False
                GoTo nxt
             End If
            
        Range("D2").Select
        Range(Selection, Selection.End(xlDown)).Select
        
        Range("D2").Select
     
     Dim x, y(), i&, j&, k&, l&, s$
    'x is the original array with the data. It starts from column C to column I, the length of
    'the array - from row 1 to the last filled cell in column C
    x = Range("C1:I" & Cells(Rows.Count, 3).End(xlUp).Row).Value
    'y is the output array, '1 to 5' means that it contains 5 columns
    ReDim y(1 To UBound(x), 1 To 5)
    
    With CreateObject("Scripting.Dictionary")
        .CompareMode = 1
        For i = 1 To UBound(x)
            'if values in column H on the sheet = ...
            If x(i, 4) = "Overtime" Or x(i, 4) = "Overtime On Saturday" Or x(i, 4) = "Overtime On Sunday" Or x(i, 4) = "Saturday Premium" Or x(i, 4) = "Sunday Premium" Or x(i, 4) = "Travel" Or x(i, 4) = "Travel Saturday" Or x(i, 4) = "Travel Sunday/Holiday" Then
                s = x(i, 2) & x(i, 4)    'BEMSID&HOURS_DESCR is the unique key
                'if key already exists in the dictionary, we sum AMOUNT
                If .exists(s) Then
                    k = .Item(s): y(k, 5) = y(k, 5) + x(i, 7)    'y(k, 5) is 'AMOUNT'
                Else 'if key not exists
                    j = j + 1: .Item(s) = j 'add key in the dictionary,
                    ' and fill the output array
                    y(j, 1) = x(i, 2): y(j, 2) = x(i, 1) 'column BEMSID
                    y(j, 2) = Split(x(i, 1), ",")(0)  'column EMPLOYEE, surname only
                    y(j, 3) = x(i, 4): y(j, 4) = x(i, 7) 'column HOURS_DESCR
                    y(j, 4) = "" 'column Value, not clear-need column to be blank so ok
                    y(j, 5) = x(i, 7)    'column AMOUNT (Units)
                End If
            End If
        Next i
    End With
    If j = 0 Then Exit Sub
    ErrHandler:
                 MsgBox "No data to import this month"
    Exit Sub
                    
    Windows("LM.xlsm").Activate
    Sheet2.Activate
    'Workbooks.Open Filename:="N:\PAYROLL\Leanne\LM\FILE TO IMPORT.xlsx"
    'Workbooks.Open Filename:=ThisWorkbook.Path & "\FILE TO IMPORT.xlsx" 'or so, if all files are in same folder
    With Sheets(2)
        .UsedRange.ClearContents
        .Columns(1).NumberFormat = "@"
        .[a1:e1].Value = Array("BEMSID", "EMPLOYEE", "HOURS_DESCR", "AMOUNT", "UNITS")
        .[a2:e2].Resize(j).Value = y()
       
        
    End With
      
      Application.DisplayAlerts = False
    
        
        'sFileNames = Application.GetSaveAsFilename(fileFilter:="All files (*.*), *.*", Title:="Please save import template")
          'If sFileNames = "False" Then Exit Sub
    
        'get row count
        Range("A1").Select
        Selection.End(xlDown).Select
        rownumber = ActiveCell.Row
        
        Range("A1").Select
        
        Columns("A:E").Select
        ActiveWorkbook.Worksheets("Sheet2").Sort.SortFields.Clear
        ActiveWorkbook.Worksheets("Sheet2").Sort.SortFields.Add Key:=Range("C2:C90") _
            , SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
        With ActiveWorkbook.Worksheets("Sheet2").Sort
            .SetRange Range("A1:E" & rownumber)
            .Header = xlYes
            .MatchCase = False
            .Orientation = xlTopToBottom
            .SortMethod = xlPinYin
            .Apply
        End With
        Range("A1").Select
        Sheet1.Select
        
    
    
           Exit Sub
        
        Windows("LM.xlsm").Activate
        Sheet1.Select
       MsgBox (iReply = "Select 2nd Step of Macro Process")
    nxt:
      MsgBox "No data was found"
    End Sub

  9. #9
    Forum Contributor
    Join Date
    09-06-2011
    Location
    northern ireland
    MS-Off Ver
    Excel 365
    Posts
    180

    Re: I am using scripting dictionary method -If no data - need a message box -

    Hello - many thanks for your help but its not working. I think you are concentrating on if there is no BEMSID then close the workbook but BEMSID will always be in the file which is why the file is remaining open. The scripting dictionary is specifically looking at x(i,4) for:

    Overtime
    Overtime On Saturday
    Overtime on Sunday
    Saturday Premium
    Sunday Premium
    Travel
    Travel Saturday
    Travel Sunday/Holiday

    Its when none of the above are within the file that I need the macro to close the weeklyFN workbook - does that make sense?

    Kind regards
    Leanne

  10. #10
    Forum Expert OnErrorGoto0's Avatar
    Join Date
    12-30-2011
    Location
    I DO NOT POST HERE ANYMORE
    MS-Off Ver
    I DO NOT POST HERE ANYMORE
    Posts
    1,655

    Re: I am using scripting dictionary method -If no data - need a message box -

    Are you trying to exit if the file you open has no data in it? If so, check if C1 is blank.
    Good luck.

  11. #11
    Forum Contributor
    Join Date
    09-06-2011
    Location
    northern ireland
    MS-Off Ver
    Excel 365
    Posts
    180

    Re: I am using scripting dictionary method -If no data - need a message box -

    the file will always have data in it - but I am specifically pulling out the

    Overtime
    Overtime On Saturday
    Overtime on Sunday
    Saturday Premium
    Sunday Premium
    Travel
    Travel Saturday
    Travel Sunday/Holiday

    It when there is no data specifically for x(i,4) for the above names

    Cheers

  12. #12
    Forum Expert OnErrorGoto0's Avatar
    Join Date
    12-30-2011
    Location
    I DO NOT POST HERE ANYMORE
    MS-Off Ver
    I DO NOT POST HERE ANYMORE
    Posts
    1,655

    Re: I am using scripting dictionary method -If no data - need a message box -

    Then I suspect you simply want to check the Count of the dictionary and exit if 0?

  13. #13
    Forum Contributor
    Join Date
    09-06-2011
    Location
    northern ireland
    MS-Off Ver
    Excel 365
    Posts
    180

    Re: I am using scripting dictionary method -If no data - need a message box -

    Hi

    How would I put that into code?

    Thanks
    Leanne

  14. #14
    Forum Expert OnErrorGoto0's Avatar
    Join Date
    12-30-2011
    Location
    I DO NOT POST HERE ANYMORE
    MS-Off Ver
    I DO NOT POST HERE ANYMORE
    Posts
    1,655

    Re: I am using scripting dictionary method -If no data - need a message box -

    Well actually, looking at your code, you already have
    If j = 0 Then Exit Sub
    so you just need to add a message box
    If j = 0 Then
     Msgbox "No data to add this month"
     Exit Sub
    End If

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

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