Need help to edit code

RAJESH1960

Banned for repeated rules violations
Joined
Mar 26, 2020
Messages
2,313
Office Version
  1. 2019
Platform
  1. Windows
Hello guys
This code was written by JohnnyL. It is a perfect code but I forgot to mention one condition in my query. So I need help to edit the code. The code runs correctly when there is a #N/A error in column F in the List of ledgers sheet. I want to add one condition in it. If there is not a single error in column F then the code should display a message box stating that "All Ledgers Available.". Right now the code shows an error when there is no error in column F at this line
Rich (BB code):
 Sheets("MasterData").Range("B2").Resize(.Count) = Application.Transpose(.keys)
Query Code to get Ledger names from another sheet.xlsm
 

Excel Facts

Which Excel functions can ignore hidden rows?
The SUBTOTAL and AGGREGATE functions ignore hidden rows. AGGREGATE can also exclude error cells and more.
If I delete Mercury from the list in LIst of Ledgers sheet column A then the code runs right without any error.
 
Upvote 0
Replace:

VBA Code:
        Sheets("MasterData").Range("B2").Resize(.Count) = Application.Transpose(.keys)                              ' Display unique values on Sheets("MasterData")
    End With
'
    Application.ScreenUpdating = True                                                                               ' Turn ScreenUpdating back on
'
    CodeCompletionTime = Timer - StartTime                                                                          ' Stop the stop watch
    CodeCompletionTime = Format(CodeCompletionTime, ".#####")                                                       ' Prevent scientific notation results
    Debug.Print "Time to complete MoveDataToDifferentSheets = " & CodeCompletionTime & " seconds."                  ' Display the time elapsed to the user (Ctrl-G)
'
    Application.Speech.Speak "This code completed in, , , " & CodeCompletionTime & " seconds."                      ' Provide audio result
End Sub

With

VBA Code:
        If .Count > 0 Then
            Sheets("MasterData").Range("B2").Resize(.Count) = Application.Transpose(.keys)                          ' Display unique values on Sheets("MasterData")
        Else
            CodeCompletionTime = Timer - StartTime                                                                  ' Stop the stop watch
            MsgBox "All Ledgers Available."                                                                         ' Display message to user
            GoTo Continue                                                                                           ' Jump to Continue:
        End If
    End With
'
    CodeCompletionTime = Timer - StartTime                                                                          ' Stop the stop watch
'
Continue:
    Application.ScreenUpdating = True                                                                               ' Turn ScreenUpdating back on
'
    CodeCompletionTime = Format(CodeCompletionTime, ".#####")                                                       ' Prevent scientific notation results
    Debug.Print "Time to complete MoveDataToDifferentSheets = " & CodeCompletionTime & " seconds."                  ' Display the time elapsed to the user (Ctrl-G)
'
    Application.Speech.Speak "This code completed in, , , " & CodeCompletionTime & " seconds."                      ' Provide audio result
End Sub
 
Upvote 0
Solution
Perfect. Just like you JohnnyL.?
 
Upvote 0

Forum statistics

Threads
1,215,777
Messages
6,126,835
Members
449,343
Latest member
DEWS2031

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top