Hi guys,
here are some basics which will help you always while writing the macro
1) To declare the workbook:
Dim wb1 As Workbook
Dim ws1 As Worksheet
2) To set the workbook to be used in program :
Set wb1 = Workbooks("Book1.xls")
Set ws1 = wb1.Sheets(1)
now, "ws1" will correspond to first sheet of "Book1.xls"
2) To write a value in a cell:
if i want to write "Hello excel" in cell B3 then just set the workbook as tole in 1 and 2
ws1.Cells( 3,2 ) = "Hello Excel"
here 3 --> row and 2--> column i.e. B in this case.
3) to take the value of the cell for operations (for eg : compare value with some constant):
Dim abc as integer
abc = ws1.Cells( 3,2 ).Value
This will assign the content of cell "B3" to variable "abc"
Next, I will give some sample code snippets to do magic with excel.
As always , please let me know anything you would like to do with excel @ kashiwar.h@gmail.com
Thanks,
Himanshu
Thursday, August 6, 2009
Wednesday, August 5, 2009
Creating Button on Excel and attaching it with macro
Hi guys,
This is how you can create the button on excel and associate it with the macro you have wrote
For Excel 2003
step 1: Go to view
step 2: In Excel 2003 and in earlier versions of Excel, click Option Button on the Forms toolbar, and then draw the outline of the button on the sheet.
For Excel 2007
Step 1:Click the Microsoft Office Button, and then click Excel Options.
step 2: Click the Customize category, select All Commands in the Choose commands from list, select Option Button (form control), and then click OK.
Following Steps are similar in both versions
Step 3: Select any cell in the worksheet.
Step 4:In versions of Excel that are for Microsoft Windows, right-click the option button, and then click Assign Macro.
Step 5:In versions of Excel that are for Macintosh, press COMMAND while you click or press CTRL while you click, depending on your operating system version. Then, click Assign Macro.
Step 6: In the Assign Macro dialog box, click the name of the macro that you want to assign to the option button, and then click OK.
Now that we have learnt how to create a macro and assign it to a button on excel from next blog I will start giving small tips in the form of code snippets.
Let me know if there is anything specific that you want me address @ kashiwar.h@gmail.com
Take care,
Himanshu
Subscribe to:
Posts (Atom)