Excel VBA Basics #10 - Looping through a database and analyzing cells based on criteria

  Рет қаралды 274,878

ExcelVbaIsFun

ExcelVbaIsFun

Күн бұрын

📊 Free Workbooks: www.excelvbaisfun.com/links?u...
🥷Join Excel Ninja Pro: www.excelvbaisfun.com/ninjapr... Months FREE On Annual Plan Auto Applied)
🥷Excel Ninjas FB Group: www.excelvbaisfun.com/xlninjas (Free downloads, Trainings, Live Q&A and more)
Loop through a sample database instantly to find a custom answer or message to the user! Download here: excelvbaisfun.com/mdocs-posts/...
Fantastic Developer Tools:
🔒 Transform Any Excel File Into A Locked EXE: www.excelvbaisfun.com/secure-... (25% off with code ‘25OFF’)
🟡 Create Custom Installers: www.excelvbaisfun.com/custom-...
👋 Business Inquiries, Consulting, Comments, etc: www.excelvbaisfun.com/contact/

Пікірлер: 163
@KevinPGA
@KevinPGA 10 жыл бұрын
I hope you never take these videos down. I learn something new EVERY time I watch them. VBA is so deep, how in the world did we figure out software like this before the internet?!?!?!?!? Thanks Daniel!
@ExcelVbaIsFun
@ExcelVbaIsFun 10 жыл бұрын
lol! Thanks Kevin! Yes, I don't think any of us would know Excel worth a crap without Mike (ExcelIsFun channel). Just learning Vlookup from him is enough to get everybody hooked! Thanks for the comment and the "Like". Dan
@ExcelVbaIsFun
@ExcelVbaIsFun 10 жыл бұрын
Merry Christmas everyone. I hope God blesses you richly this upcoming year. Remember, you ARE a success!! Believe it, be it! Blessings my friends!! Dan
@aaronmailhot9370
@aaronmailhot9370 7 жыл бұрын
Thank you so much for your kind and encouraging words as I embark to put together a similar Excel VBA course for my company.
@mikedrop137
@mikedrop137 10 жыл бұрын
Hey Dan, LOVE your videos. I work with a MONSTER of a macro program at work to perform monthly reports and your videos are training me to not only understand how it works, but also to venture off and make my own automated reports! Thanks for setting aside the time to do this. It is GREATLY appreciated.
@philipclarke6277
@philipclarke6277 5 жыл бұрын
Hi Dan, I love your simple and straight forward style. I have an estimating spreadsheet that is the data to produce a PDF summery report. Column 1 is category (eg: Building, Painting), column 2 is description, column 6 is line total. The logic is to record each line where columns 6 Line Total is greater than zero (hide all others), then store category, description and line total as variables (and copy to new worksheet). Then when printing the worksheet to PDF, group each category together and calculate sub total. EG: 3 lines for building selected at $200, $300, $400 with the building category sub total of $900 printed in the report. Then move onto the next category etc. I also want to auto size the rows and remove any blank rows and columns from the PDF report so I don't get multiple empty pages. Many thanks, Phil
@ExcelVbaIsFun
@ExcelVbaIsFun 11 жыл бұрын
Yes, working on making this more organized as I get spare time. Sorry for the delay, gotta make time for my 9 month old. Thanks for your comments, great ideas! Dan
@querrythis
@querrythis 2 жыл бұрын
I have gone through the first 10 series and the syntax is now much clearer me. Thanks for relieving my headaches.
@ExcelVbaIsFun
@ExcelVbaIsFun 2 жыл бұрын
That's awesome!
@u10ajf
@u10ajf 10 жыл бұрын
Thanks very much for posting this series it's really helpful. There were plenty of examples of one-off VBA tricks and ideas before but a progressive series like yours is so much more useful to people like myself who are trying to build up their skills.
@ExcelVbaIsFun
@ExcelVbaIsFun 10 жыл бұрын
Andrew, You're very welcome. I'm planning on buckling down and doing a series on making reports on raw data to help the community build even more awesome skills. Thanks, Dan
@theseventhfinger
@theseventhfinger 8 жыл бұрын
Thanks so much for this lesson i am just wondering what is the name of this workbook you are working at? I cannot find it in the dropbox you provided..
@cjuwells
@cjuwells 10 жыл бұрын
Hi Dan. Enjoying videos, also been looking at Mikes. Just wondering if you could advise title of this workbook as couldn't find it on dropbox, will type a few rows just so I can follow along
@elgunkhalilov
@elgunkhalilov 3 жыл бұрын
i dont know if you are still making videos or not but i really appreciate your efforts. Thank you for these videos. I am a fan of Mike and i am currently becoming a fan of you also. Thanks Again!!
@Geronimo3201
@Geronimo3201 11 жыл бұрын
Dan, I just want to add my endorsement of your mission and your work. Thank you!
@benwann9144
@benwann9144 7 жыл бұрын
This video is awesome for helping to improve my knowledge of loops and how to apply them in my projects.
@ExcelVbaIsFun
@ExcelVbaIsFun 7 жыл бұрын
Hi Ben, So glad this is helpful! Thank you for the positive comments! Keep up the good work, my friend! Thanks Dan
@sapnasuri1
@sapnasuri1 9 жыл бұрын
Awesome Videos... Have learnt a lot from Mike's Videos and now learning VBA from your video's... Its helping a lot for my professional growth. Dan I am planning to implement this for a project will post my queries in case will find any problem... Great Learning :)
@andrewwright6381
@andrewwright6381 10 жыл бұрын
These videos are great! You're doing an amazing job!
@ExcelVbaIsFun
@ExcelVbaIsFun 10 жыл бұрын
Thank you andrew!!
@rdevdass
@rdevdass 7 жыл бұрын
Hi , is it possible to get the workbook for follow up the examples screened in the videos
@victorbarlian
@victorbarlian 8 жыл бұрын
Hi Dan, just wondering do you have the file for this particular video ? Many Thanks !
@ExcelVbaIsFun
@ExcelVbaIsFun 11 жыл бұрын
Wow! I appreciate that and yes, Mike is super cool. Thanks for your comments and enthusiasm. As always, please feel free to leave a question or project idea. Dan
@mariuszmilosz5223
@mariuszmilosz5223 8 жыл бұрын
I think I will like VBA ... many thanks
@maciejmyslinski7820
@maciejmyslinski7820 7 жыл бұрын
Looks amazing! Thanks Dan!
@ExcelVbaIsFun
@ExcelVbaIsFun 11 жыл бұрын
Thanks so much Jan!
@saat876
@saat876 8 жыл бұрын
Hi Dan, great videos as usual. I took your course on Udemy and enjoyed it as well. A small request: can you upload the code you type in each video as either an attachment, or place all lines of code pertaining to each group of videos in your play list in one document? That would help a lot. Thanks a gain, you rock!
@ardeshiraqayi9976
@ardeshiraqayi9976 5 жыл бұрын
You're one of the best ... Thank you soooooooo much ..!
@michaelmartin6145
@michaelmartin6145 8 жыл бұрын
Hey I cannot access your worksheets so I can follow along? Anyway you help so I can go through all of your videos and follow along?
@salvallala7202
@salvallala7202 9 жыл бұрын
Hey. Great videos! Thank you so much for posting things. Do you by any chance know exactly which file the data is in? I cannot find the sample data at all and cant practice until I have the sample data? Is there anyway you can tell me the name that it would be under in your dropbox? Thanks!
@ExcelVbaIsFun
@ExcelVbaIsFun 11 жыл бұрын
Maggie, absolutely we can do something on incrementing dates. Do you mean like a SpinButton (up/down arrows) that changes the date upward and downward?Thanks!
@MohammadTaha
@MohammadTaha 10 жыл бұрын
this macro performs something like SUMIFS function>>>> that's very very good thank you
@ExcelVbaIsFun
@ExcelVbaIsFun 10 жыл бұрын
Thanks Mohammad, I appreciate the comments and the "Like".
@MohammadTaha
@MohammadTaha 10 жыл бұрын
You're welcome Dan
@shihabkhan3218
@shihabkhan3218 9 жыл бұрын
Very helpful videos. Thanks a lot for cutting through the bulshit and keeping your videos relevant :P Appreciated
@lezluis1974
@lezluis1974 10 жыл бұрын
Muy bueno el vídeo y la explicación sobre como asignar valores a los rangos saludos
@Tony223618
@Tony223618 9 жыл бұрын
just want to know which workbook this vedio refered to? i saw too many workbook in the dropbox...
@ExcelVbaIsFun
@ExcelVbaIsFun 10 жыл бұрын
Starting a new channel for Piano Lessons, learn by Chord and play by ear! Check it out here: How to Play Piano by Chord - Beginning Chords - C
@sdveffwvee9825
@sdveffwvee9825 7 жыл бұрын
Hi Dan, don't you need to declare what counter is before you use it?
@aaronmailhot9370
@aaronmailhot9370 7 жыл бұрын
I was thinking the same thing. I agree with you on principal that one should ALWAYS assign a variable to a known value before using it. I.e. in this case, I would've liked to see a 'counter = 0' line prior to the counter being iterated in the for-loop (where it is first 'used', i.e. appears on the right-hand side of the '='). HOWEVER, technically you do NOT need to initialize this variable as VBA will interpret it as an Integer, which will ALWAYS have a default value of the number 0 when first used. Note here that VBA knows this variable is an Integer even without a 'Dim counter As Integer' line because Daniel added the variable to the known data in Cell(x, 3), which is an Integer and so defines the counter variable based on this context (at least I am 95% sure this is how it works).More info on this topic can be found at: stackoverflow.com/questions/7626967/vba-variable-array-default-values. Lastly I note that DEFINING all variables with a 'Dim ... As ...' line is also good practice, however Daniel notes in a previous video that this level of rigor is not required and I would agree; I think it somewhat more important to explicitly initialize variables than define them, if only for readability (at least as far as VBA goes).
@ExcelVbaIsFun
@ExcelVbaIsFun 11 жыл бұрын
Very welcome, Maggie.
@ExcelVbaIsFun
@ExcelVbaIsFun 11 жыл бұрын
Thanks Alex! Where I work, most people work with and are comfortable with Excel. In fact, a lot of people operate using reports in Excel, but they have to do a lot of tedious data entry and huge arduous functions to make that happen. I'm just trying to help those who want to automate Excel be empowered to do so. Do you have any videos on how to work with SQL or can you recommend some? Sounds cool. Dan
@DatabaseDesigns4U
@DatabaseDesigns4U 10 жыл бұрын
Great video! Thank you for sharing! :)
@ExcelVbaIsFun
@ExcelVbaIsFun 10 жыл бұрын
No prob bob!
@benoitj9588
@benoitj9588 7 жыл бұрын
Hey dan, would it be possible to obtain the workboos of your videos to train ? Nothing is better to learn code :( Thx for the videos !
@JohnJones-ct9pr
@JohnJones-ct9pr 2 жыл бұрын
Lovely . Thanks.
@ExcelVbaIsFun
@ExcelVbaIsFun 2 жыл бұрын
Very welcome, John!
@hasithaaththanayaka6541
@hasithaaththanayaka6541 7 жыл бұрын
THANKS A LOT... ONE DAY I WILL FINISH ALL LESSONS...
@sandysane3737
@sandysane3737 10 жыл бұрын
Hi, Great videos. Thanks for taking the time to make them. Is there a way to extract the color from a conditionally formatted cell and paste that color into another cell? Thanks in advance!
@ExcelVbaIsFun
@ExcelVbaIsFun 10 жыл бұрын
Maybe! not sure, i'll have to look into it! Good question. Dan
@karaavelilavlini
@karaavelilavlini 11 жыл бұрын
Thank u. Sorry for confusion on days and months. Actually in France, 1/4/2013 means 1st of april:) In the USA, it is 4th of January, Iguess~ I've already found it by increasing quarterly. but the logic was this. Thank u again for the videos, which are very helpful and ur post-video mentoring:)
@kazz5742
@kazz5742 10 жыл бұрын
Dan, First of all great video. Just wanted to clarify why there is only one "&" for counter ( & counter) as opposed to the variable cat/lname which has it on either side (& cat &). Is it something to do with dependent/independent variables?
@karaavelilavlini
@karaavelilavlini 11 жыл бұрын
hello, thank you for such useful videos. Do u have a video, where u explain how to inclement the dates?
@ExcelVbaIsFun
@ExcelVbaIsFun 11 жыл бұрын
icy, I'd be glad to try and help. What do you have so far? Also, I'm not sure if I understand what you're trying to do exactly. For example, what is N, as in I=1 to N? What is G supposed to mean? Are you trying to print it to the screen, is it supposed to print out on paper, or attach to some other variable, etc? Also, what are you calculating? Are you looping through cells on a page or through some list? Thanks for any clarification. Dan
@alexrosen8762
@alexrosen8762 7 жыл бұрын
Thanks for sharing but where is the workbook? I can't find it in your dropbox??
@steve2005hey
@steve2005hey 11 жыл бұрын
Thanks so so much for uploading these wonderful VBA funny videoes. I am definitely following your link for excel VBA & right now in Excel VBA Basics #10 - Looping, would I ask which excel spreadsheetes in dropbox should i be using ? Many many thanks !
@jamesbatchelor2880
@jamesbatchelor2880 10 жыл бұрын
Hi Your videos are great. How do I get the file. what's the drop box everyone is talking about
@JanBolhuis
@JanBolhuis 11 жыл бұрын
Great Video (again :))
@krn14242
@krn14242 11 жыл бұрын
Great job.
@dadahawk2003
@dadahawk2003 11 жыл бұрын
Hi Dan, thanks for the nice videos, it is actually a good source to learn VBA all by myself. Could you please kindly tell me what is the file name of the workbook you used in this video? I have tried a couple in the dropbox website and I couldn't find it. Thanks.
@ExcelVbaIsFun
@ExcelVbaIsFun 11 жыл бұрын
okthenhello, I've updated this video's description to contain those links. Enjoy!! Dan
@ExcelVbaIsFun
@ExcelVbaIsFun 10 жыл бұрын
I'm not sure if I follow: Depends what you have i set to and what j is set to. for example: Sub Test() i=2 j=4 cells(i,j)="blah" End Sub so in that example the cell we're referencing is row 2 column 4 aka "D2", so cell D2 would have the word "blah" in it. If you want i or j to be a different reference, you have to tell it to refer to some other area. Let me know if you'd like further explanation, i know its tricky at first! Dan
@abusarah73
@abusarah73 6 жыл бұрын
Can I ask you a question? If I have 10 combo box in a form and all of them have same row source , and I want a code to not let the same value repeat in the combo box , by making the value which choosed in one combo box disappear from others??
@niikehayova
@niikehayova 7 жыл бұрын
One comment/suggestion from me. If I use a new variable to sum up somethign, the way you use counter (counter = counter + x), I always make sure that I declare it at the start of the current sub, and null it (dim counter as integer counter=0). Sometimes, when I'm using a monther-sub function, which calls different subs consequently, I experience errors from such counter variables, which are not nulled at the start of the subs, and it's a hell to debug, so I'm always precautious.
@niikehayova
@niikehayova 7 жыл бұрын
Ah, it was mentioned before in the comments... Nevermind :)
@ExcelVbaIsFun
@ExcelVbaIsFun 10 жыл бұрын
I think a lot of the first ones I did are in the workbook called "ExcelVBAIsFun lesson 9.xlsm".
@stephenobrien9573
@stephenobrien9573 7 жыл бұрын
hi is there any way i could get a sample datasheet / worksheet with all those cells filled in accordingly ? so i can practice this >
@debasismahapatro358
@debasismahapatro358 8 жыл бұрын
great tutorials. thanks for sharing. i want to use the networkdays function of excel in a loop in VBA based on a column till the last cell. for example, i have the start date in col. C and the end date on Col D. now i want the days difference between 2 dates in col E by using the networkdays function till the col C "". can you help me on this...?
@aaronmailhot9370
@aaronmailhot9370 7 жыл бұрын
Here is the rough pseudo-code for your request: ' Assumes your data spans row 2 to row 'lr' (lastRow) ' See Dan's video above for how to set 'lr' for rr = 2 to lr Cells(rr, 5) = Worksheetfunction.NextworkDays(Cells(rr, 4), Cells(rr, 3)) next rr Alternatively you could place the ACTUAL function in the cells instead of the calculated value, which would mean it would update dynamically if column C or D changed (not sure if this is what you want). To do this, simply change the line in the for-loop to: Cells(rr, 5).Text = "=NETWORKDAYS(..., ...)"
@rnodern
@rnodern 8 жыл бұрын
I probably would have absorbed the whole dataset into an array and cycled through it in memory. It's far more efficient than lots of worksheet operations (never ever use select!!)
@aaronmailhot9370
@aaronmailhot9370 7 жыл бұрын
I feel you modern. Just bear in mind that this video is geared towards newbies/non-programmers (which I think is great!) and thus might take some work to warm them up to Arrays...and the more 'down to earth' the content is (i.e. the easier it relates to how they would manually manipulate the Excel file), the easier it will be for newbies to absorb :).
@ahmedzakikhan7639
@ahmedzakikhan7639 10 жыл бұрын
Question : Why did you use the Selection Row code? I mean to define CAT or LNAME; Can we not just name Cat = dbsheet.cells(x,4) and lname - dbsheet.cells(x,5) instead of using SelRow>>
@fanathym
@fanathym 10 жыл бұрын
I am sure you could use that as well. But the 'selection'-command allows you to change the categories 'on the fly'. Otherwise you'd have to manually change them in the code every single time for different queries.
@vijaysahal4556
@vijaysahal4556 3 жыл бұрын
very nice 👍🏻👍🏻👍🏻👍🏻👍🏻
@ohdjrp4
@ohdjrp4 10 жыл бұрын
Hey, Dan! How about making a DVD for Excel VBA, just like Mike Girvin? I will be one your buyers. Cheers!
@ExcelVbaIsFun
@ExcelVbaIsFun 10 жыл бұрын
Thanks orlando, I've been planning on it for some time. Thanks for your support! God bless. Dan
@icy1356
@icy1356 11 жыл бұрын
Thank you for your asking. N is a number, N=21. G is a given quantity of my calculation formula, there are 21 Gs, so I want to use it make 21 calculations. And then, I want to print G and its corresponding results in Excel sheet, two columns, just it, no paper. My formula is simple arithmetic, like D=G*386.4. Actually, I just input these 21 numbers in my code, because if I choose them from cells, I don't know how to print them together. Thanks.
@gerardvaneggermond9967
@gerardvaneggermond9967 5 жыл бұрын
Hello, I find your video interesting, can you now use the same formula to retrieve data and put it next to the "name, so suppose that column B contains data and would like to place it next to the name you're looking for, is that possible?
@ExcelVbaIsFun
@ExcelVbaIsFun 11 жыл бұрын
Geronimo, thank you and thank you!! and you're welcome. lol. Daniel
@ExcelVbaIsFun
@ExcelVbaIsFun 11 жыл бұрын
I can make a video, but it sure helps if you already know the name(s) of the workbook(s), the location of the workbook(s) and the sheet(s) you want to extract into your new or existing workbook. If you want ALL sheets from each workbook it becomes easier. A loop would be in order, eg. for each ws in thisworkbook.worksheets blah blah do this do that next ws. Please gimme the details and i'm sure we can come up with a lesson in the Tips N Tricks section to review this. Thanks! Dan
@omaralsharif2690
@omaralsharif2690 7 жыл бұрын
Hi Friend, just a question, I understand everything except the counter, how does VBA understands that this is accumulation ? how does the qty is combined with no identification of the counter?, you identify the Cat, you identify the lname but you didn't identify the counter (the one to the right side of the equation i.e. the one added to dbsheet), so how does the qty is combined, I don't know
@faustprivate
@faustprivate 5 жыл бұрын
If you omit to declare a variable (using Dim and specifying what type of variable it is), the default variable type will be of type Variant. A Variant is a special data type that can contain any kind of data. So, in his example, he didn't declare "counter". I personally would have declared it just to avoid confusion. Ok, so he didn't declare it, so it is automatically a Variant. When VBA encounters the code "counter = counter + dbsheets.cells(x,3)", it does this: "nothing = nothing + 1067", so at that point it knows that the variable counter will be used to store numbers. If there's more than one hit in the loop, the next time it will do "counter = counter + whatever", so let's say "counter = 1067 + 300". At that point, counter will keep on incrementing. If you were to just say counter = dbsheets.cells(x,3), then counter would only take the value of the last hit in the loop, but that's not what we want, we want the sum!
@age_of_reason
@age_of_reason 5 жыл бұрын
@@faustprivate Awesome explanation. I understand now. Thank you!
@ha21mi
@ha21mi 5 жыл бұрын
@@faustprivate " If there's more than one hit in the loop, the next time it will do "counter = counter + whatever", so let's say "counter = 1067 + 300". At that point, counter will keep on incrementing." But how does VBA know that "counter" on the right side of the equation is referring to the sum of all the previous "counters"? It's like saying x = x+3. It doesn't make sense at first sight. Do you have any link where similar instances are presented? Thank you
@RajKothari
@RajKothari 11 жыл бұрын
Hey your videos are great....Could you please share the file name in the drop-box corresponding to this video like the way Mike Grivin does....this would be Great!!
@vijaysahal4556
@vijaysahal4556 3 жыл бұрын
Verynice 👍🏻👍🏻👍🏻👍🏻
@archanaaa2514
@archanaaa2514 4 жыл бұрын
Hello sir, y u used counter in for loop. What is d use of that? I dint get
@icy1356
@icy1356 11 жыл бұрын
Hi Dan, by the way, where can attach a print-screen of my code?
@karaavelilavlini
@karaavelilavlini 11 жыл бұрын
i found the functions, dateadd and dateserial, but i still have a problem to increase by three months in the cells of excel~ maybe i should use 2 loops? one for cells and the second loop for the incremental months? i hope u can suggest the right solution. thank u in advance.
@princechadha3097
@princechadha3097 5 жыл бұрын
Sir I am unable to see VBA function in excel after press Alt f11 but before it show in excel but not now
@icy1356
@icy1356 11 жыл бұрын
Hi Dan, I have a question for you. About how to assign a list of number to a variant(G) in loop. The thing is I=1 to N, and I hope when I=1, G use the first number; I=2, G use the second one to make calculation. Finally, Print the G and the its corresponding results. Do you know what to make the code in VBA? I always have problems with assign and print.... Hope you can help me. Thanks!
@AshutoshSharma1991
@AshutoshSharma1991 8 жыл бұрын
how to get sum in one go, when i do it its taking the first value then adds another value then another,doesn't sum in one go as your code did!
@ExcelVbaIsFun
@ExcelVbaIsFun 11 жыл бұрын
Most of the initial lessons can be found on a wb named "ExcelVBAIsFun lesson 9.xlsm" For some reason, I just stuck with this one for awhile. . .
@karaavelilavlini
@karaavelilavlini 11 жыл бұрын
Thank u very much for ur quick reply. What I'm searching is easier than SpinButton. I want to increase my date (the months) by 3 months. If i start from B1=1/1/2013, C2 would be 1/4/2013, then C3=1/7/2013 etc. maybe this was not the appropriate video to ask below, but I saw increasing dates, and i thought probably somewhere u have it and I missed it. Can u suggest how to do it? I saw how u did by increasing the dates (cells(x,1)=Dates+7) but I don't want to add just 90, i want exact months.
@doriginal69
@doriginal69 8 жыл бұрын
I have a report that has spaces in it and we want to return if the value is false on an if then statement. How do you make it bypass the spaces and still keep calculating until it gets to the top?
@aaronmailhot9370
@aaronmailhot9370 7 жыл бұрын
Can you elaborate on this request? When you say 'report', is it an Excel workbook? What format is it in (columns and rows). If not a workbook, what sort of structure does it have? (assuming text file) Fundamentally though, you would simply right your 'false' check and not take any action on any other value. I.e.: If (myVal = false) Then Return Else ' Do nothing End If
@doriginal69
@doriginal69 7 жыл бұрын
Yes, your video just shows a loop through where there is something on each consecutive line. What would happen if there was a break and there was nothing and the rest of your information was another four lines down after the break. Your loop would only look if there was not break in that loop.
@DavidStone27
@DavidStone27 4 жыл бұрын
can you elaborate a little more on the logic behind "counter"?
@a.s.yeasmin1691
@a.s.yeasmin1691 8 жыл бұрын
what code is required if i want to sum up values in other cell based on criteria set in other cells
@aaronmailhot9370
@aaronmailhot9370 7 жыл бұрын
subha: grab or reproduce a copy of Dan's code above and then simply look at the 'dbsheet.Cells(thing1, thing2)' lines and modify the 'thing2' as you require. If this is a little daunting, you can explore the code as you go with 'freezing' in debug and hovering over things (as Dan teaches in previous videos). I also like to 'see' the cells I am interested in on the actual spreadsheet, which you can also do when 'frozen' in debug mode. To do so, simply select them via the 'immidiate' window in the VBA editor. E.g. put that window side-by-side with your Excel sheet and then type 'dbsheet.Cells(thing1, thing2).Select', and then hit ENTER. You don't even have to retype it each time you want to use it, just click back to that line in the immediate window and hit ENTER again. Hope that helps!
@alfietankokleong
@alfietankokleong 9 жыл бұрын
Good vid. The approach would be much faster if you simply dump it to an array and use application.match
@tgoodstuff
@tgoodstuff 10 жыл бұрын
how do i select the i in cells(i,j) i want to add the i value to another i value in a different cell(i,j)
@md.kamrulhasan9034
@md.kamrulhasan9034 6 жыл бұрын
Hi, I need little clarification. You didn't declare any data type for x and counter, how VB identifying them as variable?
@faustprivate
@faustprivate 5 жыл бұрын
by default, if you don't add the statement "Option Explicit" at the top of your module, VBA will let you type code with variables that weren't specifically declared before. So you can start any line with let's say "whatever = " or "thisismyvariable = " and this will implicitely declare these randoms words as variables of type Variant. A Variant is a special data type that can contain any kind of data. he didn't declare it, so it is automatically a Variant. When VBA encounters the code "counter = counter + dbsheets.cells(x,3)", it does this: "nothing = nothing + 1067", so at that point it knows that the variable counter will be used to store numbers. I highly recommend using Option Explicit at the top of your module to force you to declare all variables and choose a data type prior to using the variables. This will save you TONS of problems in the future. :)
@jayjayf9699
@jayjayf9699 6 жыл бұрын
I dont understand the counter bit? what does counter mean in the loop?
@xarakkhan1727
@xarakkhan1727 4 жыл бұрын
Sir please i need help I have 100 of word documents i want to extract some specific data from the documents. And want to put that in to cells.
@lequylong3731
@lequylong3731 7 жыл бұрын
thank sir. i don't understand that what is counter variable. you do not define counter so why can counter variable get value of qty column when cat =dbsheet.cells(x,4) and lname = dbsheet.cells(x,5). thank
@aaronmailhot9370
@aaronmailhot9370 7 жыл бұрын
The short answer is that all variables are ALWAYS set to a 'default' (rather than random garbage) value in VBA. In this case, Integers get set to the numeric value 0. If curious, I have a longer tirade on this topic up above, two replies under Dan's post about his piano lesson channel.
@Dopeboyz789
@Dopeboyz789 5 жыл бұрын
Can you use vba for anything
@alanl7147
@alanl7147 6 жыл бұрын
Hi, where can I find the file as the dropbox link isn't working.
@ExcelVbaIsFun
@ExcelVbaIsFun 6 жыл бұрын
Hi Alan, Please check out my new URL for workbooks library: excelvbaisfun.com/free-workbooks/ Sometimes dropbox links don't work well with many people trying to download... Thanks Dan
@patrickwessels2067
@patrickwessels2067 4 жыл бұрын
Can someone please help me loop a recorded macro I have to insert borders around550+ sections of data?
@user-pr7wv5ko8g
@user-pr7wv5ko8g 8 жыл бұрын
hi, I get error 424 object required for counter = counter + dbsheet. cells(x, 3). can you please help here?
@qinli5240
@qinli5240 10 жыл бұрын
Hi, When I hover my mouse on the code, there are no tags showing the value of any of the variables. Please help!
@pawegloger6722
@pawegloger6722 9 жыл бұрын
Variables will appear when u get to debugging mode, so type "F8"
@faustprivate
@faustprivate 5 жыл бұрын
and of course the values will only appear *after* the specific line of code is ran. if you have x = 2 on the third line of your module but you're debugging the macro and you are at the second line, it hasn't gone THROUGH line 3, so obviously at that point x is equal to nothing! Only have line 3 is ran, x will be equal to 2.
@snjpverma
@snjpverma 7 жыл бұрын
Counter = Counter + dbsheet.cells (x, 3)
@faustprivate
@faustprivate 5 жыл бұрын
counter here is a random word that he made up which is not recognized by VBA. He could have typed "MySuperDooperNiceCounter" and it would have done the same thing. To make things clearer, he should have declared it at the top of the page by typing Dim Counter as Long. By not declaring it, he let VBA "guess" what he wanted to do. It's a dangerous shortcut that most beginners shouldn't take. I recommend using the "Option Explicit" statement at the top of the page in the module. That way, the statement "Counter = Counter + 123456" would have returned an error -> "Variable not defined". So to answer your question, no Counter isn't a "reserved VBA term" like xlup or xltoleft, it's just a random name that he made up for his variable which he omitted to declare (on purpose, but somehow out of laziness!!)
@icy1356
@icy1356 11 жыл бұрын
Thank you. I have posted the PrtSc to the page, please check it.
@ExcelVbaIsFun
@ExcelVbaIsFun 11 жыл бұрын
Maggie, this is absolutely do-able. So, just to be clear, when you say 1/1/2013, and then 1/4/2013 you're talking jan 1 then april 1, right? My US mind was corrupted to think you were incrementing by 3 days and i got confused for a second. Okay, try using DateAdd function: LastDate= range("b1") for x= 2 to whatever cells(x,1)=DateAdd("m", 3, LastDate) LastDate=cells(x,1) next x
@thealexgalaxyoriginal
@thealexgalaxyoriginal 11 жыл бұрын
Hey man you are a good teacher. I don't think it's a great topic because you can get that same output using SQL with probably 10% of the effort. But still, this is a great intro to Excel VBA.
@tgoodstuff
@tgoodstuff 10 жыл бұрын
Im trying to make a function that works as the sumproduct function in excel
@melishan94
@melishan94 7 жыл бұрын
how can I do a vlookup in vba with 2 search criterias and with using diffrent lookup sheets? Please, I need urgent help!
@HbninfotechTutorials
@HbninfotechTutorials 7 жыл бұрын
You can use Application.WorksheetFunction or Range.Formula Property or Evaluate Method etc. There are so many ways. But you have to tell me what exactly you are looking for with sample data.
@aaronmailhot9370
@aaronmailhot9370 7 жыл бұрын
Melishan: I do not know if there is a way to do this with VLOOKUP as you are looking to chain two 'filters' together and your first VLOOKUP will only return ONE match, not ALL matches. Rather, I would encourage you to try to modify Dan's code that he goes over in your video to do what you want; it shouldn't be as hard as it sounds. The basic execution here would go something like (looks better if you copy-paste to VBA editor): ' which column's data do you want to return when the criteria match? retCol = 1 ' Loop over each row of your output data (where you would've written the VLOOKUP) For each row R1 of outputSheet ' Where you will write the result for each row myOutCell = Cells(R1 , myOutCol) ' First Criterion myCrit1 = Cells(R1 , myCrit1Col) ' Second Criterion myCrit2 = Cells(R1 , myCrit2Col) ' Now loop through input data (that would've been first parameter in VLOOKUP). This loop is similar to Dan's in this video. For each row R2 in inputSheet ' Define inputCrit's here, like myCrit's above ... ' Look for a match of BOTH criteria If (myCrit1 matches inputCrit1) And (myCrit2 matches inputCrit2) Then myOutCell = Cells(R2, retCol) ' Found match so go to next iteration of outer loop Goto nextOutRow End If Next R2 ' End inner for-loop 'If we got here, we didn't find a match myOutCell = "No match found!" 'landmark for the 'Goto' line above nextOutRow: Next R1 ' End outer for-loop Hope that helps, let me know if you need more help hammering out the details from there!
@mpilo01
@mpilo01 5 жыл бұрын
Hi, i am having difficulty with all the links. Can anybody assist me, will be much appreciated. Thanks
@KD-xy8kq
@KD-xy8kq 3 жыл бұрын
without declaring variables lr and selrow, how is the code working????
@ExcelVbaIsFun
@ExcelVbaIsFun 11 жыл бұрын
i meant for it to put a space after x=2 to whatever. didn't work. Dan
@brigittahalasova2031
@brigittahalasova2031 6 жыл бұрын
The lastrow command doesn't work. it. just. does. not. when i press F8 and hover over it, I see lr = Empty. Any ideas?
@ExcelVbaIsFun
@ExcelVbaIsFun 6 жыл бұрын
Most people have problems because they type XIUP or X1UP, instead of XLUP. Maybe try that first? Thanks Dan
@brigittahalasova2031
@brigittahalasova2031 6 жыл бұрын
Hello Dan, this was not my case. I still can't figure out what the problem was but i downloaded the file again and went step by step and now it works just fine. Sorry about that and thanks for replying :) Brigitta
@ExcelVbaIsFun
@ExcelVbaIsFun 6 жыл бұрын
Nice work! Glad you got it working!
@vulcanscorpio
@vulcanscorpio 9 жыл бұрын
I notice he called this a database. Which of course it is. Isn't this the function of Access? Wouldn't that just be easier to use for this function?
@Diallo268
@Diallo268 6 жыл бұрын
couldn't you have just used the with statement for the ThisWorkbook.Sheets("db") instead of the set and having to type it multiple times?
@faustprivate
@faustprivate 5 жыл бұрын
Yes, he could have. It's a more Advanced function and I believe that he is going step by step, with baby steps.
@aperxmim
@aperxmim 9 жыл бұрын
You can use the letter "c" this is not reserved in Excel VBA
@age_of_reason
@age_of_reason 6 жыл бұрын
This can be done with a SUMIFS formula. Much easier.
@faustprivate
@faustprivate 5 жыл бұрын
VBA offers multiples ways to achieving the same results. SUMIFS would work perfectly but is more Advanced, which isn't the goal of this video. But you are right :)
⬅️🤔➡️
00:31
Celine Dept
Рет қаралды 51 МЛН
Luck Decides My Future Again 🍀🍀🍀 #katebrush #shorts
00:19
Kate Brush
Рет қаралды 8 МЛН
Excel Macro Class 3 - Looping through Ranges & Working with Cells
31:16
Which is the Fastest VBA Method For Reading Tables?
8:39
Excel Macro Mastery
Рет қаралды 41 М.
The Ultimate Guide to Copying Data using Excel VBA
31:05
Excel Macro Mastery
Рет қаралды 62 М.
Class Modules in VBA: Made Super Simple
17:43
Excel Macro Mastery
Рет қаралды 30 М.
Excel VBA Create SQL Query on Worksheet
17:06
The Excel Cave
Рет қаралды 15 М.
Using VBA to Enter Data into an Excel Table
14:08
MyExcelOnline.com
Рет қаралды 56 М.
VBA For Loop - A Complete Guide
12:36
Excel Macro Mastery
Рет қаралды 78 М.
Excel VBA For Loop Data Matching
10:01
Coding Module
Рет қаралды 14 М.
⬅️🤔➡️
00:31
Celine Dept
Рет қаралды 51 МЛН