Thursday, 15 June 2017

What is Scripting.Dictionary? What is Array? in VBA excel macro



Hello all,
What is Scripting.Dictionary?
Nice question … don’t worry am here to answer. Before that What is Array?
Array is a data structure (Don’t ask what is data Structure) that contain group of element with the same data type.
Example:
Dim ArrayExample
ArrayExample=array(“Fail” ,”Mark”)


Or


ArrayExample(0)=”Fail”
ArrayExample(0)=”Mark


(If you need to know about array and dimension comment below)


Now Dictionary :


Dictionary object is similar to PERL associative array…(Google it What is PERL array?)
Dictionary object can stored any value in the array and each stored items associated with a
unique key. We can retrieve data using key.( see the example then you will understand more)


Example:
Dim DictionaryExample   (Don’t write Dim DictionaryExample() )
Set  DictionaryExample = CreateObject(“Scripting.Dictionary”)


DictionaryExample.Add  “key”, “Fail”
DictionaryExample.Add  “keeey”, “Mark”


See the example now and read the explanation again.


(I know about your laziness read here) The value “Fail” and “Mark” stored in array, the stored items “Fail” and “Mark” associated with a unique key “key” and “keeey”. We can retrieve data “Fail” and “Mark” using key “key and Keeey”.


Program for array: (Do copy past like a programmer)





Sub ArrayExampleProgram()
Dim ArrayExample
ArrayExample = Array("Fail", "Mark")

Debug.Print ArrayExample(0)
Debug.Print ArrayExample(1)
End Sub

Sub ArrayExampleProgram1()
Dim ArrayExample(1)
ArrayExample(0) = "Fail"
ArrayExample(1) = "Mark"

Debug.Print ArrayExample(0)
Debug.Print ArrayExample(1)
End Sub 

Program for Data Dictionary:









Sub DictionaryExampleProgram()
Dim DictionaryExample
Set DictionaryExample = CreateObject("Scripting.Dictionary")


DictionaryExample.Add "key", "Fail"
DictionaryExample.Add "keeey", "Mark"


Debug.Print DictionaryExample.Item("key")
Debug.Print DictionaryExample.Item("keeey")
End Sub




(bye byeeeeeeeeee......)
 

Wednesday, 14 June 2017

How to write Macro coding? How to run macro coding ? How to see macro coding? How to Enable Developer Mode?



How to open VBA and run macro program in Excel


How to See Macro Coding?
Open New excel File …. And Press ALT + F11 it will redirect you to the coding window.

Else open Excel and find Developer mode and press Visual Basic.
Step: 1


How to enable Developer mode on excel?
OMG… if you can’t able to find Developer mode then go to File - > Options on your Excel And find Customize Ribbon and check Developer. Now do the above process to view the coding window.
Again Step 1:



Step 2:


How to Write Macro Coding? How to Run Macro Coding?

Click “ThisWorkbook” on project window (Left side )
And write your coding like below one (Don’t copy paste just 3 line you can type) ,Now press F5 to run macro coding.


Coding:


Sub Test()
Msgbox “Hello World”
End sub