vba sintax

janefo

New Member
Joined
Sep 4, 2011
Messages
7
Hi I am new to vba and trying to understand it. I read that the right way to write methods is :
"ObjectName.MethodName
argument1, argument2" , but exactly what does ObjectName and MethodName represent? and are arguments the actions I want to happen?
Thank you for your help,

janefo:confused:
 

Excel Facts

Back into an answer in Excel
Use Data, What-If Analysis, Goal Seek to find the correct input cell value to reach a desired result
Code:
Range("A1:A10").Replace What:="Bob", Replacement:="Joe"

The range is the object, Replace is the method, and "Bob" and "Joe" are the arguments
 
Upvote 0
For example

Code:
Range("A1:E5").Sort Key1:=Range("A1"), Order1:=xlAscending, Header:=xlGuess, OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom

Range("A1:E5") is the Object

Sort is the method

Key1 and so on are the arguments.

Please do not use tiny writing.
 
Upvote 0
This could go on for a while ... :biggrin:
 
Upvote 0
Objects are code "things" the have properties and methods associated with them. As others have posted, a Range is such a code "thing". It has properties (I'm assuming you are familiar with these) such as Address, Formula, Font, Count, Interior, and a whole host more... some of these properties have properies of their own, such as Font, which has properties such as Name, Color, Bold, Size and so forth (and it is even possible for those properties to have properties of their own as well). Properties are equivalent, in a loose sort of way, to variables and/or constants... they have values assigned to them, sometimes the programmer can change these values like with a variable and sometimes the programmer can't change their values like with a constant (constants are declared with a Const statement in case you haven't come across them yet). Objects also have methods. Methods are equivalent to Subroutines (Sub's) and Functions... they either perform an action (like a Sub) or they perform an action and return a value resulting from that action (like a Function). Subroutines (not macros though) and Functions can have arguments, and so to can Methods. Arguments are chunks of data that you pass into the a Subroutine or a Function which they need to perform their actions. For example, think of of the Int function... by itself, Int can't do anything because you haven't told it what number to truncate down to an integer. The number you pass into the Int function, done via parentheses such as Int(1.23), is an argument. A Subroutine or Function associated with an object is called a Method (same name applies to both of them) and, like its subroutine and Funciton counterparts, it too can have arguments. So, so simplify this all for you... Methods are nothing more than Subroutines and Function associated only with the object being referred to into which you can pass pieces of data required by the Method in order for it to be able to perform its action.
 
Upvote 0

Forum statistics

Threads
1,224,599
Messages
6,179,828
Members
452,946
Latest member
JoseDavid

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