Free Excel VBA Macro Tutorial - VBA Macro - Functions - For Each Loop

Опубликовано: 06 Май 2026
на канале: KeeshtuTechnology
44
1

Free Excel VBA Macro Tutorial - VBA Macro - Functions - For Each Loop - Using Functions in Macro - youtube #youtubechannel #youtubevideo #vba #vbamacro #vbamacros
hi welcome to technology platform so let me continue on within the second session so earlier sessions we talked about how to capture the values in the cell that is like row value or column values um now how to uh use the functions so the continuation of frustrations like how to use the functions here i want to demonstrate here so now in the previous example so i'm just adding

another row p so in that also i'm capturing only three values just for our sample now here i'm adding 1 2 3 and these values capturing in two columns now if we run f5 the book one value will be showing like this sorry so now let me run this

so i captured here one two three and one two three now i i i will add this this this and i have to capture here so how do i do that let me see here now this is c values now let me check this c and then i just simply adding this plus

a plus b now i am going to run this if you go to excel sheet 1 plus 1 2 2 plus 2 4 3 plus 3 6 now now this i want to do wire function so this is me directly used in this same sub process but i want to take a separate session and then i want to call that function so how do i do that so for that i'm using function as a keyword

in function so the function name is simply i would put it like sum function and i want to pass variable so parameter i will mention like pattern one as this is integer

comma parent true as integer

so now it's a function assume that b plus c that is a a equal to b plus c this is what we want to do for example um a equal to b plus c

so the result a is 1 plus 1 equal to a equal to 2 so this is what we want to do that for this we created a function here now i'm not doing anything i just simply put it like same function

so this is what i want to do so i told you like a equal to b plus c the same thing i'm using some function param1 press arrow so now instead of this let it be so we can put it in d value let's see in b so here

i'm going to call

some function open bracket close bracket now if you see this if you open i'm getting this pattern one as integer and parent to us integer so the param one as integer and param two as integer is like this one oh i had removed this for example this one this one so one plus one equal to two so this is parallel one and this is param two now see this sum function what is the parameter i want to pass so the same thing i am simply using this a this is one of the function i am not going to use plus instead of that i am using comma comma the pattern two values d

now i am closing this now if you see here the sum function a comma b will call it out here now let me run it in a debug mode f8 again f eight f eight f eight a five now if you see here the value is one value is one here

now 1 1 so this will be 2 2 the same value sum function now this will goes to here

the param1 value is 1 pair and 2 value is 1 because the a value 1 1 2 so if you click here 1 1 2

n function this is 2 so we no need to do anything here so instead of that we can use it as a functions to achieve the process now i will press f5 now you will go to the excel sheet and you can see the same result so this is not only for some so whatever you want to do do it for example um now what i'm going to do here is like parameter and instead of that i will put it like 10 into 10 you can do it so now what i'm going to do here is like i want to run it sample run

now see this 20 40 60. so let me run it one by one here one one one so if it is very difficult for you to find out what is happening here and there for that uh you can use debug.print so let me end it i'll show you here go to view immediate window is there now click on this immediate window

here

now let me run it a5

f8 again f8 again if right align effect now see this immediate window is one

okay so let me add it here something like this in a double quotation first value

and then i will put and

let me stop this entry again run it f8 f8 f8 f8 the first value one so if you have any difficulties then you can put it like the first value is and space let's clear this stop this f eight f eight of eight f eight f eight f now you will see this first value is 1 so the same thing i am going to use it

i used to hear second value and i want to use it here the sum

i'll use d because d is the sum function so now we can run it f eight the second value is one functions call it out now the sum result value is so here you can use this debug.print and then you can get it whatever you need so it is not only you can do it minus or whatever it is that's yours so