Skip to content

Instantly share code, notes, and snippets.

Sub check()
Set Rng = ThisWorkbook.Sheets(1).Range("B1:B20")
Rng.RemoveDuplicates Columns:=Array(1), Header:=xlYes
End Sub
@erajanraja24
erajanraja24 / VBA to remove duplicates in a given Range
Created June 2, 2016 17:57
VBA to remove duplicates in a given Range
Sub check()
Set Rng = ThisWorkbook.Sheets(1).Range("A1:C12")
Rng.RemoveDuplicates Columns:=Array(1, 2, 3), Header:=xlYes
End Sub
@erajanraja24
erajanraja24 / VBA to remove duplicates in a given range for specified columns
Created June 2, 2016 18:13
VBA to remove duplicates in a given range for specified columns
Sub check()
Set Rng = ThisWorkbook.Sheets(1).Range("A1:D13")
Rng.RemoveDuplicates Columns:=Array(1, 2), Header:=xlYes
End Sub
@erajanraja24
erajanraja24 / VBA to remove duplicates in an unknown range for specified columns
Last active June 2, 2016 18:20
VBA to remove duplicates in an unknown range for specified columns
Sub check()
Set Rng = ThisWorkbook.Sheets(1).UsedRange
Rng.RemoveDuplicates Columns:=Array(1, 2), Header:=xlYes
End Sub
@erajanraja24
erajanraja24 / VBA to remove duplicates in an unknown range and unknown columns
Created June 2, 2016 18:52
VBA to remove duplicates in an unknown range and unknown/dynamic columns
Sub check()
'Determing the last column
LastCol = ThisWorkbook.Sheets(1).UsedRange.Columns.Count
'Determining the last row
LastRow = ThisWorkbook.Sheets(1).UsedRange.Rows.Count
'Determining the Range
@erajanraja24
erajanraja24 / Example 1
Created June 21, 2016 16:10
Excel VBA Scope of variables
Sub Procedure_Scope_1()
Dim i As Integer
i = 5
Debug.Print "Variable i value in Procedurecheck1 is " & i
End Sub
Sub Procedure_Scope_2()
Debug.Print "Variable i value in Procedurecheck2 is " & i
End Sub
@erajanraja24
erajanraja24 / Example 2
Created June 21, 2016 16:11
Excel VBA Scope of variables
Dim var1 As Integer
Sub Module_Scope_1()
var1 = 20
Debug.Print "Value of var1 in Module_Scope_1: "; var1
var1 = var1 + 15
End Sub
Sub Module_Scope_2()
@erajanraja24
erajanraja24 / Example 3
Last active June 21, 2016 16:21
Excel VBA Scope of variables
'In Module 1
Option Private Module
Public var1 As Integer
Sub Public_Scope_1()
var1 = 20
Debug.Print "Value of var1 in Public_Scope_1: "; var1
var1 = var1 + 15
@erajanraja24
erajanraja24 / How to get the search results from google for the given keywords
Created July 4, 2016 16:27
Automating Internet explorer with Excel VBA Part 2
Sub iepart2()
Dim ie As Object
'
Set ie = CreateObject("internetexplorer.application")
With ie
.Visible = True
.navigate "https://www.google.co.in"
@erajanraja24
erajanraja24 / Automatic web form filling
Created July 31, 2016 17:26
Automate Internet Explorer with Excel VBA Part 3
Sub automaticformfilling()
Dim ie As Object
Set ie = CreateObject("internetexplorer.application")
With ie
.Visible = True
.navigate "http://newtours.demoaut.com/mercuryregister.php"
'Wait for loading