VBA Basic usefull Code


1.  Runtime EXCEL VBA error handling code

Below Code copy:-Green highlight text you can change
-------------------------------------------------------------------------------------------------
Sub  My_Error_handlingCode()
On Error GoTo NitinPathError

Workbooks.Open Filename:="C:\Users\kumarnii\OneDrive - adidas\1-Master Database\01-Other Master Database 2015-2020\1_20_REEBOK_MASTER_DATABASE.xlsx"
Exit Sub
NitinPathError:
MsgBox ("Path Not Find/Not connect Internet, Pls check Internet connection")
End Sub

---------------------------------------------------------------------------------------------------------

2. UserForm show code:-

Below Code copy:-Green highlight text you can change
---------------------------------------------------------------------------------------------------------
  Sub one_Click_list1()
Userform_name.Show
End Sub
----------------------------------------------------------------------------------------------------------

3. Open File  Excel VBA code:-

Below Code copy:-Green highlight text you can change
-------------------------------------------------------------------------------------------------
Sub  myfileopen()

Workbooks.Open Filename:="C:\Users\kumarnii\OneDrive - adidas\1-Master Database\01-Other Master Database 2015-2020\1_20_REEBOK_MASTER_DATABASE.xlsx"
End Sub
---------------------------------------------------------------------------------------------------------

4. Open Folder VBA code:-

Below Code copy:-Green highlight text you can change
-------------------------------------------------------------------------------------------------
Sub Nitinvbaapp_Setup()
Dim str_folder As String
str_folder = "C:\NitinVbaApp\Setup\"
Call Shell("explorer.exe " & str_folder, 3)
End Sub
-------------------------------------------------------------------------------------------------

5. File save as code:-

Below Code copy:-Green highlight text you can change
-------------------------------------------------------------------------------------------------
Sub myfilesave()

ActiveWorkbook.SaveAs ("C:\DailyEntryCopy\myfilename.xlsx")
End sub()
-------------------------------------------------------------------------------------------------

6. Application Delay /Waiting Code:-

Below Code copy:-Green highlight text you can change
-------------------------------------------------------------------------------------------------
Sub myapplicationdelay()
' delay 2 secound
Application.Wait Now + TimeValue("00:00:02")
End sub()
-------------------------------------------------------------------------------------------------



-----------------------------------------------------------------------------------------------

Active Sheet Copy Excel Vba code:-

' Use for copy select sheet a new workbook for send mail.
Sub CopySheet()
Dim WB As Workbook
Dim AW As Window
Dim Newfilename As String
Dim Path1 As String
'ActiveWorkbook.Save


Path1 = "C:\DailyEntryCopy\"
If Dir(Path1, vbDirectory) = "" Then
                Shell ("cmd /c mkdir """ & Path1 & """")
                End If
'Application.Wait Now + TimeValue("00:00:02")
MsgBox ("file Save Location" & Path1)



Newfilename = InputBox("Enter File name ", "Enter a Number")

Set AW = ActiveWindow
For Each SHT In AW.SelectedSheets
    Set TempWindow = AW.NewWindow
    SHT.Copy
    TempWindow.Close
Next
'Save file
ActiveWorkbook.SaveAs (Path1 & Newfilename & " " & Format(Now(), "DD-MMM-YYYY hh mm AMPM") & ".xlsx")

End Sub
------------------------------------------------------------------------------------------------------------------

Printout Excel VBA Code:-


'Below Pivot printout code you can record macro and change green code:-
----------------------------------------------------------------------------------------------
Sub PrintOutCarton()
'
' PrintOutCarton Macro
'
' Keyboard Shortcut: Ctrl+Shift+A
'
   Range("b6").CurrentRegion.Select
    Range("B6").Activate
    Selection.Borders(xlDiagonalDown).LineStyle = xlNone
    Selection.Borders(xlDiagonalUp).LineStyle = xlNone
    With Selection.Borders(xlEdgeLeft)
        .LineStyle = xlContinuous
        .ColorIndex = 0
        .TintAndShade = 0
        .Weight = xlThin
    End With
    With Selection.Borders(xlEdgeTop)
        .LineStyle = xlContinuous
        .ColorIndex = 0
        .TintAndShade = 0
        .Weight = xlThin
    End With
    With Selection.Borders(xlEdgeBottom)
        .LineStyle = xlContinuous
        .ColorIndex = 0
        .TintAndShade = 0
        .Weight = xlThin
    End With
    With Selection.Borders(xlEdgeRight)
        .LineStyle = xlContinuous
        .ColorIndex = 0
        .TintAndShade = 0
        .Weight = xlThin
    End With
    With Selection.Borders(xlInsideVertical)
        .LineStyle = xlContinuous
        .ColorIndex = 0
        .TintAndShade = 0
        .Weight = xlThin
    End With
    With Selection.Borders(xlInsideHorizontal)
        .LineStyle = xlContinuous
        .ColorIndex = 0
        .TintAndShade = 0
        .Weight = xlThin
    End With
    ActiveWindow.SelectedSheets.PrintOut Copies:=1, Collate:=True, _
        IgnorePrintAreas:=False
End Sub
------------------------------------------------------------------------------------------------------

Solution blur image post on blogger | Screenshot image show blur.

 How to solution blur image post in blogger .

Following below simple step.
Step 1:- Screenshot any image.
Step-2 :- Open MS paint then paste image .
Step 3:- File save in .PNG format. 
Then upload image on blogger or website . image show original ,not blur.

This trick 100% working . if problem to solve . please comment .

How to Disable Right click mouse on website or Blogger

How to Disable Right click mouse on website or Blogger.

Copy below html code and paste blogger add gadget.

------------------------------------------------------------------------------------------

 <script>

document.addEventListener("contextmenu", function(event){

event.preventDefault();

alert('This Website Right Click is Disabled');    

}, false);

</script>

---------------------------------------------------------

How to count blank cells in filtered list



How to count blank cells in filtered list

Please Like  and share facebook page for more comupter tips and tricks:-https://www.facebook.com/computertipsupdate

Example:-

=SUBTOTAL(3,$A$4:$A$11)-SUBTOTAL(3,B4:B11)



About Me

author Click here for Connect FB

Click here for Linkedin