How to get the Last Row in VBA(The Right Way!)

  Рет қаралды 166,680

Excel Macro Mastery

Excel Macro Mastery

Күн бұрын

Пікірлер: 215
@Excelmacromastery
@Excelmacromastery 3 жыл бұрын
FLASH SALE: 25% off my Effective Excel VBA course before Saturday 14th September: 👉courses.excelmacromastery.com/courses/Effective_Excel_VBA Let me know what you think about the methods in the comments. Make sure to download the source code with examples and the custom functions that I created.
@mikheilchigogidze4224
@mikheilchigogidze4224 3 жыл бұрын
Can you please also make Python channel. Sooner the better
@khalidalisawi8037
@khalidalisawi8037 3 жыл бұрын
pleas how I can download the source in this great video.
@khalidalisawi8037
@khalidalisawi8037 3 жыл бұрын
I have seen many videos but many codes just in your video especially to find the last cell and to select range with using the last row and last column as a reference to a cell. thank you for your work and how to download the codes and examples
@thomaswaldmann9264
@thomaswaldmann9264 2 жыл бұрын
Excellent. One small problem - if the sheet is empty it will find nothing and give back a range with nothing -> Err = 91. if range is nothing then Last = 0 else Last = range.row endif
@fullpowerrolf
@fullpowerrolf 2 жыл бұрын
Thanks a lot for the video. I tried it out, and I think it does not count merged cells. So if the last unmerged cell is in C3 and there is a merged cell from D4 to E4 your last cell will be C3. Find function does not properly work with merged cells I think.
@Metalocif
@Metalocif 3 жыл бұрын
Didn't know you had a KZbin channel. I teach VBA, and I always point my students to your website as the best resource there is.
@Excelmacromastery
@Excelmacromastery 3 жыл бұрын
Thanks Alexandre.
@tha2irtalib343
@tha2irtalib343 3 жыл бұрын
Thanks Paul for sharing such a great job , no one like you .. no one ever .
@rogerirvine4420
@rogerirvine4420 3 жыл бұрын
In the final example, I love the fact that you can (if required) insert some starting point coordinates. Excellent. Seeing your patient build-up was worth the wait. Thanks Paul. I've learnt a load of real, 'outside the box' approaches to many things that are useable and adaptable in 'real world' settings since I signed up for your course. (And I've promised myself that I WILL get to finish it!)
@Excelmacromastery
@Excelmacromastery 3 жыл бұрын
Glad you like it Roger.
@rogerh2694
@rogerh2694 3 жыл бұрын
Irvine, CA?? Also in OC!
@LuizFeijotheGuitar
@LuizFeijotheGuitar 3 жыл бұрын
@@Excelmacromastery hi sir Paul, i love Excel, and i starting to learn about VBA, from Where i Begin?
@free3690
@free3690 3 жыл бұрын
Such an elegant solution, thank you for sharing your wealth of knowledge!
@KurtSchwind
@KurtSchwind 3 жыл бұрын
I've probably solved the 'last Row' or 'last Column' a dozen ways and none of them are as clean and consistent as that 'Find' method. Thanks.
@cpro671
@cpro671 3 жыл бұрын
The find method is an interesting way to approach this problem and it works well in most circumstances. But in testing I did find that if you' are working with a protected sheet that also has the Hidden checkbox selected, the functions will generate an error and return Cells (1,1) from the error handling code. If you manually hide rows or columns the functions work correctly. Also, if filters are turned on you will get the last filtered row, not the last of all rows. Returning the last filtered row could potentially be useful as long as you are aware and not looking for the last actual row of data.
@АлексейСоков-ь8и
@АлексейСоков-ь8и Жыл бұрын
Thanks for your note!
@YDysgwrAraf
@YDysgwrAraf 3 жыл бұрын
Working with and navigating our way around unstructured data is an absolutely key skill for spreadsheet developers, and all of these techniques have a place in out toolbox. Knowing the appropriate tool for the job in hand is the crucial thing to learn. I recently worked on a Java project where we were reading spreadsheets into Java library objects, and my fellow developers were astonished by the ease with which I could, using knowledge from years of work with Excel, find my way around the jagged and unpredictable data.
@PraiseTheLord1611
@PraiseTheLord1611 3 жыл бұрын
How dare you defeat all our "tried and true" methods! ;) Thanks for the video
@TheGallantTitan
@TheGallantTitan 2 жыл бұрын
I struggled with the issue of not properly selecting an area of Jagged data until I watched this video. Thanks for helping me out.
@Monochromatic_Spider
@Monochromatic_Spider 3 жыл бұрын
Missed a big one with .end(xlUp). It works on VISIBLE rows. So if you have filter mode on and some content rows are filtered out then you're not actually finding the last content row, just merely the last visible content row. Certainly something to keep in mind. Still, this is my general goto because of how quick and simple it is. As for Find, I suspect (without having checked) that it has some performance overhead. It uses the regular workbook "Find and Replace" function to look through content but of course stopping after the first result of literally anything should help. Do keep in mind that the search term shows up if users manually open the Find and Replace function.
@SolidSnake59
@SolidSnake59 3 жыл бұрын
Well I thought about performance as well, but after all this are only 2 searches, so it shouldn't be so bad.
@joukenienhuis6888
@joukenienhuis6888 Жыл бұрын
Thank you for this very helpful video. I think the lastRow function is especially handy when you want to enter new data. But then again if you work with named Data Ranges in Excel, it can automatically add the last entered data if you are using a form
@rjaquaponics9266
@rjaquaponics9266 3 жыл бұрын
This video was incredible. It's like juggling, while smoking a cigar, while riding a bike, while skiiing down fresh powder all at the same time! Bravo!
@Excelmacromastery
@Excelmacromastery 3 жыл бұрын
Thanks
@mariaalcala5159
@mariaalcala5159 3 жыл бұрын
Great method to find the last row! Thanks for sharing your knowledge!!!
@eduarchavarria
@eduarchavarria 3 жыл бұрын
Paul, great as always, thanks. Searching for the last row of data is one task that I perform very often.
@hotflashfoto
@hotflashfoto 2 жыл бұрын
Most of the macros I manage were inherited, and thankfully they have column A fully populated with no spaces. However, they were written in the days when there were only 65,536 rows. Recently, there was data that went past 70,ooo rows and it decided that the last row was row #1 until I updated it. At first, I was skeptical of a better way, but using Find looks like a good way of doing it regardless of sheet length. Thanks for sharing!
@itsdaj
@itsdaj 2 жыл бұрын
Thanks for the great content. Where was this video 15 years ago?
@johnwayne8059
@johnwayne8059 3 жыл бұрын
That's simply great! Well done Paul!👍👍👍
@Excelmacromastery
@Excelmacromastery 3 жыл бұрын
Thanks John
@aldofernandez2013
@aldofernandez2013 Жыл бұрын
Thank you so much! you dont have idea on how much this will help me
@jimfitch
@jimfitch 3 жыл бұрын
Really looking forward to this, Paul!
@Excelmacromastery
@Excelmacromastery 3 жыл бұрын
I hope you'll like it Jim.
@jimfitch
@jimfitch 3 жыл бұрын
@@Excelmacromastery Like it? I love it, Paul! I interrupted workday to watch this instead of viewing in evening/weekend (usual practice), took detailed notes while watching, & already downloaded source code. I plan to add your code (modified to my naming & commenting practices) to a class module that I created for often-used subs/functions; it works like Access's DoCmd. Thank you for walking thru the first 4 methods before teaching Range.Find. I've used different approaches in the past, but now will standardize on your code. Thank you for sharing this with us!
@sasavienne
@sasavienne Жыл бұрын
Thank you so much for sharing this great video. The knowledge you share is priceless.
@woodpigeon01
@woodpigeon01 3 жыл бұрын
Good one Paul. It’s one of the first question you ask yourself when you are writing Excel code.
@julianevans2256
@julianevans2256 2 жыл бұрын
Excellent presentation Paul !
@zaksept
@zaksept 3 жыл бұрын
Perfect timing, I was just doing a job today and I needed to copy 30 sheets into one. They all had different amount of rows ranging from 20 - 300. However, xlDown woudn't work because the last row had data in random columns, not always col A. What I ended up doing was a for loop where I pulled 300 rows from each sheet, and paste them into the summary sheet. Afterwards I ran a separate macro to delete the blank lines with nothing on them. This would have saved me a couple steps.
@Excelmacromastery
@Excelmacromastery 3 жыл бұрын
Glad it was helpful Zach.
@amennkonou7161
@amennkonou7161 3 жыл бұрын
I have been waiting for this longtime.Thank you Mr Paul KELLY
@Excelmacromastery
@Excelmacromastery 3 жыл бұрын
You're welcome
@Info-God
@Info-God 3 жыл бұрын
Great and useful help for those who do heavy programming in VBA-Excel. Thanks Paul.
@Excelmacromastery
@Excelmacromastery 3 жыл бұрын
You're welcome
@renemarot544
@renemarot544 6 ай бұрын
Thanks. Very didactic. Nerver thinked about using find this way. One cave at with find is hidden rows and hidden columns. If you have some of them find just seems to ignore them.
@edrobinson8248
@edrobinson8248 6 ай бұрын
absolutely brilliant. note that we can use Clear All to remove formating rather than having to close the whole WorkBook? :-)
@officetricks6303
@officetricks6303 3 жыл бұрын
Got the most wanted video at the right time.
@pbs36
@pbs36 3 жыл бұрын
As usual, great choice of topic for a video and good solution for the problem..
@khalidalisawi8037
@khalidalisawi8037 3 жыл бұрын
really it was a great video that I saw. I saw many videos before but it was the best.
@rogerio067072
@rogerio067072 3 жыл бұрын
🤯🤯🤯🤯 wow you never disappoint me in always bringing new knowledge to what i have been doing. Outstanding!!! Will try this method with my data. I always need to check the amount of data i have to deal with and this will help me a lot
@Excelmacromastery
@Excelmacromastery 3 жыл бұрын
Thank you!
@scottgaines2677
@scottgaines2677 3 жыл бұрын
Another great video Paul!! Very informative! Thanks so much 👍🏻😃
@Excelmacromastery
@Excelmacromastery 3 жыл бұрын
Thanks Scott.
@ScholarGypsyOx
@ScholarGypsyOx Жыл бұрын
Interesting as always, but I do wonder if this is a bit of a sledgehammer to crack a nut. When reading in data that may have lots of blank cells, I design the sheet so that it has a row of headers at the top, with no gaps, and then a "ref" or similar field in the first column which is non-empty for every valid record, and a blank cell denotes the end of the data. (one could automate this of course, using code on the sheet to detect when changes are made and check column 1 is non empty, unless the cell below contains "ZZZ"). Then I use something like set rg = range(sh1.range("top_left").end(xltoright), sh1.range("top_left").end(xldown)), although I think current region would work fine and normally give the same results (except where one has a row with a blank in column 1...).
@canews8971
@canews8971 Жыл бұрын
Wow! excellent video. Instant sub. Thanks!
@itlife4555
@itlife4555 2 жыл бұрын
could you please tell what's the screen recording tool you used? it seems perfect.
@patricknicholson5556
@patricknicholson5556 10 ай бұрын
Excellent compare and contrast. Do you have advice on how to handle/trap those cases where the range you're testing might be empty?
@patricknicholson5556
@patricknicholson5556 10 ай бұрын
NM. Your eh: captures the situation perfectly.
@Scrags-Gudale
@Scrags-Gudale 3 жыл бұрын
Excellent video. A nice addition would have been showing people how to turn the returned column number into a letter.
@troysiemers
@troysiemers 3 жыл бұрын
Actually, I have some sheets where I want to count cells with no data but only color format so the UsedRange "bug" is actually a feature. Very nice!
@Excelmacromastery
@Excelmacromastery 3 жыл бұрын
It does work perfect for that:)
@gianlucacolangelo8204
@gianlucacolangelo8204 2 жыл бұрын
this is absolute awesome!! thank you very much!!!!
@edrobinson8248
@edrobinson8248 3 жыл бұрын
the problem with USedRAnge is not so much the formated cell but when you clear (of formats as well as contents) the formatted cell. It still remains in the USedRange unless you properly delete it ;-) BTW: Excellent video as usual.
@Excelmacromastery
@Excelmacromastery 3 жыл бұрын
Glad you like it Ed
@NoName-Since-2022
@NoName-Since-2022 3 жыл бұрын
Paul, please explain also how to get FIRST column, FIRTS row in range. Thanks in advance!
@ahmed007Jaber
@ahmed007Jaber 9 ай бұрын
Amazing must watch it again. Are you on linkedin?
@davidunger7425
@davidunger7425 3 жыл бұрын
Great video Paul, thanks.
@josejn2007
@josejn2007 3 жыл бұрын
Thanks for sharing.
@josebejaranop4005
@josebejaranop4005 3 жыл бұрын
I long to see this premiere Greetings from Santa Cruz Bolivi🇧🇴
@Excelmacromastery
@Excelmacromastery 3 жыл бұрын
Thanks Jose
@karnabudhathoki5311
@karnabudhathoki5311 3 жыл бұрын
@ Excel Macro Mastery...I have seen your videos on class modules but I would love more.......... not specific but about anything But organising application as a whole because I have faced problems while altering or adding features to already functioning applications..
@Excelmacromastery
@Excelmacromastery 3 жыл бұрын
Class Modules is a big topic. I may do more in the future on some of the concepts involved in designing classes.
@stephencorbeil9538
@stephencorbeil9538 3 жыл бұрын
Good job Paul! Seriously going to be helpful with a future project.
@jhgpsimons
@jhgpsimons 3 жыл бұрын
Never thought of it using find for that, thanks
@Excelmacromastery
@Excelmacromastery 3 жыл бұрын
You're welcome.
@robbaron1206
@robbaron1206 3 жыл бұрын
Find is a no-go for me because it changes the settings that users use on the front end. When I hit Ctrl f or Ctrl h I expect that the settings from my last search haven't changed. I had a coworker use a vba find with a whole workbook setting. Then I would try to replace on a sheet and it would replace in the workbook. Very frustrating.
@davescott7680
@davescott7680 3 жыл бұрын
Just use Public Function ResetFind() Dim r As Range Set r = ThisWorkbook.Sheets(1).Cells(1, 1) r.Find What:="", LookIn:=xlFormulas, LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:=False, SearchFormat:=False r.Replace What:="", Replacement:="", ReplaceFormat:=False End Function
@shakhobiddinnakiev6767
@shakhobiddinnakiev6767 Жыл бұрын
does it work in listbject ?
@davidunger7425
@davidunger7425 2 жыл бұрын
Paul, this was an excellent video, thanks very much. However, the download link doesn't seem to be working, tried it for the last 3 days, just "spins".
@AL-tl7ov
@AL-tl7ov 2 жыл бұрын
how to do ctrl+arrow down as loop until last cell found in vba? that would be appreciated
@soumyodipkanrar3032
@soumyodipkanrar3032 3 жыл бұрын
Thanks! Very useful video.
@geertvancompernolle2586
@geertvancompernolle2586 2 жыл бұрын
Download link in the e-mail received doesn't seem to work (anymore?).
@mihalydozsa2254
@mihalydozsa2254 Жыл бұрын
How can I find the last row if there is an expanded array formula in the longest column?
@Rice0987
@Rice0987 3 жыл бұрын
Nice work! But how effectively to use Find method in code?
@szidzse
@szidzse 3 жыл бұрын
For each cell in range? Could be 1 row, or column. Im using that since i've met with an anomaly (same method /end(xlup).row /different row values in col a or col b, last row were the same)
@itsdaj
@itsdaj 2 жыл бұрын
The link to the code is not loading. Any chance it will get fixed?
@xaviereng5754
@xaviereng5754 3 жыл бұрын
hi thank u for the lesson. idk how to code for my project and need help. 2 given arrays are list of discounts for office supplies and furnitures Using macro, we needa extract the correct discount from the 2 arrays and match it with the correct product in excel sheet. to be coded into a blank row of discount for the lists of products in excel sheet.
@elecirlisboa9155
@elecirlisboa9155 3 жыл бұрын
Excelente aula, parabéns!
@Josxou
@Josxou 2 жыл бұрын
Do your methods for finding the last row and last column work with merged cells or hidden rows/columns?
@yeahnick4260
@yeahnick4260 10 ай бұрын
I would like to know why you are using LookIn:=xlFormulas and not LookIn:=xlValues ​​because xlFormulas returns cells containing functions?
@UzmanExcel
@UzmanExcel 3 жыл бұрын
Last method has a slight disadvantage. It gives an error while there is no data at sheet instead of one. So, you can wrap up your function with an if statement wheter sheet contains data or not by using native counta function
@geoffstrickler
@geoffstrickler 3 жыл бұрын
Conclusion, there is no simple way to determine the last row or column containing data in Excel or VBA. There are ways, just no simple, reliable function unless you write one, or include a third party library. Still, his was a useful video for several reasons: 1. It includes the code for such a function, which as you note, needs an exception handler for an empty worksheet. 2. It shows the strengths and weaknesses of the 4 commonly used methods. The fact that two of them don’t work on protected worksheets means I will never use those two methods. Not every worksheet is protected, but I refuse to use methods that will fail when I do have protected worksheets enabled. 3 .end(xlup) and end(xltoleft) look to be the most generally useful, simple functions, as long as you’re aware of their limitations regarding “jagged” data in the final row/column. When you can’t ensure the final row/column will always contain in one specific column/row, then Paul’s functions with your modification is the way to go.
@Pedritox0953
@Pedritox0953 3 жыл бұрын
Wonderful videos !
@Excelmacromastery
@Excelmacromastery 3 жыл бұрын
Thanks
@strannostrannovasrr
@strannostrannovasrr 3 жыл бұрын
Does it also work if the last row(s) with data are filtered or hidden and you stil wants to know the real last row on the sheet?
@nenavatjyothi3968
@nenavatjyothi3968 2 жыл бұрын
I have one doubt, regarding vba macro not working properly when I run on more than 100 rows. Can You plz help me how to resolve it?
@deshmukhvv
@deshmukhvv Жыл бұрын
i am not able to see code at given link
@robertowerneck6902
@robertowerneck6902 3 жыл бұрын
Great Video! Thanks! 👍
@kleber_bispo
@kleber_bispo 2 жыл бұрын
hi. the link to source code isn't working.
@luca1319
@luca1319 3 жыл бұрын
Could you please explain the meaning of "on error goto eh"?
@TSSC
@TSSC 3 жыл бұрын
The TOC doesn’t mention working with Excel tables (ListObject). Will you cover this as well?
@Excelmacromastery
@Excelmacromastery 3 жыл бұрын
When using a Listobject(Table) you get back a range using DataBodyRange. You can treat it like the range from CurrentRegion and Used Range.
@TSSC
@TSSC 3 жыл бұрын
One needs to remember that the list may contain no data (only header row) and then referencing the DataBodyRange won’t work.
@Excelmacromastery
@Excelmacromastery 3 жыл бұрын
@@TSSC You can use ListRows to check if the table has no data. If Table.ListRows > 0. I may do a video on Tables in the future. It's worth at least one full video.
@TSSC
@TSSC 3 жыл бұрын
Exactly. I guess the video would be appreciated. ListObjects are quite handy.
@mdf9035
@mdf9035 3 жыл бұрын
I have multiple sheets in one workbook.I need to combine all sheet as one master sheet and whatever I modify in master sheet it should reflect changes in respective sheet automatically
@govindkumarsodani3290
@govindkumarsodani3290 Жыл бұрын
Very useful
@miless2111sutube
@miless2111sutube 3 жыл бұрын
another excellent video, thank you. One quick question; you were using the shJagged to refer to the sheet "Jagged data" how does this work? I was expecting you to have to type worksheets("jagged data") but ShJagged is much cleaner.
@coloringontheline
@coloringontheline 3 жыл бұрын
Option Explicit Private Const cTxt as string = "I found: " Public wb as Workbook Public ws as Worksheet Public sub exmplSub() Dim rng as Range Dim STxt as String Set wb = Thisworkbook Set ws = wb.sheets(1) Set rng = ws.cells.find("*") If Not rng = Nothing Then STxt = rng.value2 Elseif ws.Usedrange.Cells.Count
@coloringontheline
@coloringontheline 3 жыл бұрын
Apologies if I'm being annoying but I wanted to give an example of what I meant by explicit declarations and the module and procedural level. Please also forgive me if 2 more things: 1 If I assumed too little of your knowledge; and 2 if that example isn't perfect. Im pretty sure it's right. But I just hand typed it on my phone directly into the comments lol. I hope you or literally anyone reading this finds it helpful even a tiny tiny bit. Im gonna go now 😅
@miless2111sutube
@miless2111sutube 3 жыл бұрын
@@coloringontheline Thank you Zachary for replying however I am sorry that my skills don't allow me to understand how this response addresses my question about using shJagged to refer to the sheet "Jagged data".
@coloringontheline
@coloringontheline 3 жыл бұрын
@@miless2111sutube got it, okay. No worries. My fault. Let me see if I can try again. If this doesn't help maybe I can make a 1-2 min video on it or something. I'm not a KZbinr so it wouldn't be professional. But it might break the communication issue. Here: Windows Hotkeys. (Or use the View menu at the top of the VBA Editor window) Property Explorer = Ctrl+R Property Window = F4 "(Name)" is the first "Property" listed in the "Property Window" when you select "Sheet1" of your VBAProject from the "Project Explorer". "Sheet1" can be found when the section "Microsoft Excel Objects" of your VBAProject is expanded. Which by default, it should be. Press Ctrl+R to select the Project Window. Use your Up and Down Arrow Keys to highlight "Sheet1." Then, Press F4. (not Alt+F4 lol, that closes windows) once you've pressed F4. The property window will either be selected if already open, or it will open if it was closed. The item selected after pressing F4 is the "(Name)" property. You can either click on it, or simply press F4 again. Then, start typing a new name. Whatever you name an objects "(Name)" here is called it's "Codename" and it is what's happening, and how he refers to the sheet as "ShtAnything" So if the first Worksheet in your Excel is called "Catalog List" And you changed the "(Name)" to "CataList" You could use all of the following: Worksheets(1).Range Worksheets("Catalog List").Range Sheets(1).Range Sheets("Catalog List").Range CataList.Range You cannot refer to it as: Thisworkbook.CataList.Range Workbooks("Book1").CataList.Range If you delete the worksheet. The (Name) property doesn't transfer to the next sheet. Meaning. If you use the (Name)/Codename in your code a lot. You'll want to not delete the sheet. If you plan to delete it. Try using the Declarations I talked about earlier. You can only change (Name)/Codename during "Design Time" meaning you can't make a macro change (Name). You have to type it by hand for each object you want to name. It's not a recommended convention for programming for the reasons I mentioned earlier. However, that doesn't mean that you can't or shouldn't do it if it's what's best for you or your projects. Happy to help more if this doesn't work out or if I didn't communicate well again. Links below are to Microsoft Docs Reference Material about this question. Note: this does mean that you can actually just use the default codename from the get-go. Like, Sheet1.Range No change to anything necessary. docs.microsoft.com/en-us/office/vba/language/reference/user-interface-help/use-the-properties-window docs.microsoft.com/en-us/office/vba/api/excel.worksheet.codename
@ryangraham6878
@ryangraham6878 Жыл бұрын
@@coloringontheline dude. you are the real MVP here. a year later, helping me out. I used "Sheet3" and it worked for me.
@martinstannard2859
@martinstannard2859 3 жыл бұрын
Great video as always Paul! BTW, just think that method could be slightly improved too…. Firstly, I’d run a “dummy Find” afterwards in the Function, to set the Find arguments back to default (otherwise, next time the User tries to use Find in that session, they will unwittingly use these quirky argument settings of course). Also, the other small downfall I find with this method is that Find will not work on a protected sheet if the cells formulas are set to Hidden (even if the cells have just values, it still won’t work). A way around this is to check using CountA, this would normally be too slow to loop though each row from the last row backwards, but I find that you can get this to run really quickly by using a loop that uses a “shrinking range” as you check.
@Excelmacromastery
@Excelmacromastery 3 жыл бұрын
Thanks Martin. Some good ideas there.
@martinstannard2859
@martinstannard2859 3 жыл бұрын
@@Excelmacromastery no probs Paul, btw I work in VBA pretty much full time, and your videos have really helped me out along the way. Big thanks:)
@JelleWie
@JelleWie 3 жыл бұрын
Why no speed comparison? That's the biggest thing I care about in such function atm
@BroersJo
@BroersJo 10 ай бұрын
if filters are turned on you will get the last filtered row, not the last of all rows. Returning the last filtered row could potentially be useful as long as you are aware and not looking for the last actual row of data. Is there a solution for this problem?
@JeffJefferyUK
@JeffJefferyUK 3 жыл бұрын
But define "wrong"! If my method (which I'm happy to grade as 'clunky', by the way!) works, then it's not wrong, am I right?
@Excelmacromastery
@Excelmacromastery 3 жыл бұрын
Which method is it? Why not use the best one. It isn't any more effort.
@JeffJefferyUK
@JeffJefferyUK 3 жыл бұрын
@@Excelmacromastery I agree. I was mostly teasing. :-) My method is laughable. Essentially it assume/relies on a contiguous range of data, then tests 'Is this cell blank? No? Move down one cell and try again.' until it finds a blank cell. It's risky!
@TSSC
@TSSC 3 жыл бұрын
=RIGHT() Also, it happens that I add data to a list and need to find the last row. I think I, in most cases, would avoid populating data via code below an existing list. Depending on the situation, I’d either add it in a new set of columns (separated from the existing data, possibly defining a name for the top-left cell to facilitate future referencing) … or simply use a new worksheet. Contiguous data. By the way, pedagogic video (as expected).
@stephenmackenzie9016
@stephenmackenzie9016 3 жыл бұрын
Would be good to know how autofilter affects any of the methods…
@mchaudhary4510
@mchaudhary4510 2 жыл бұрын
Hi - Find method doesn't work if data on a sheet is filtered, in that case we need to clear the data but since sheet is protected so find will also not work, so we can write another function based on usedrange and counta worksheet function that will work in each situation
@Pankaj-Verma-
@Pankaj-Verma- 2 жыл бұрын
Thank you.
@BGHmariam
@BGHmariam 3 жыл бұрын
I am getting a subscript out of range error with the cells.find method
@muhittinyetgin97
@muhittinyetgin97 2 жыл бұрын
I need to use the same program on different computers. It works fine in one but some codes not working in the other.Especially if the codes starting with "application" then its not working.why could it be.
@tknaved
@tknaved 2 жыл бұрын
Hi, i need a help....how can i make range a varible insted of using Range("A1:D4") ...i want A,1,D,4 all must be daynamic variable kindly support
@pacman22XD
@pacman22XD 3 жыл бұрын
What about the speed?
@mkparker99
@mkparker99 2 жыл бұрын
I've been trying to get this to work with a spilled array, but it only goes to the row with the formula and ignores the spilled values. Is there a way to pick these spilled values in the lastrow/lastcolumn/lastcell functions?
@bxyhxyh
@bxyhxyh 2 жыл бұрын
change xlFormulas to xlValues
@mkparker99
@mkparker99 2 жыл бұрын
@@bxyhxyh Thank you!
@peterwrth5640
@peterwrth5640 3 жыл бұрын
As always, great tutorial Paul. I got excited at seeing functions which will allow me to protect sheets and return "currentregion" which otherwise fails. But, cannot seem to download the code. Have no ad blockers active. Link sends me to a youtube page with your icon for watching the video. Tried creating the functions myself, but i'm missing something. Any solution would be much appreciated. I really need these functions.
@Excelmacromastery
@Excelmacromastery 3 жыл бұрын
Send me an email and I'll send you the code. Paul ExcelMacroMastery
@MohAboAbdo
@MohAboAbdo 3 жыл бұрын
Thank you so much
@saviodcunha8741
@saviodcunha8741 2 жыл бұрын
Thanks !!
@Saleh.Wardak
@Saleh.Wardak 2 жыл бұрын
How to find last row of printing page
@robertw236
@robertw236 3 жыл бұрын
Great insights into the failings of native methods and very useful method to get around them. Extremely useful. Thanks for sharing your insights with the community.
@wayneedmondson1065
@wayneedmondson1065 3 жыл бұрын
Hi Paul. Great tutorial! I tend to use the Range.End method in simple cases when I know the column or row to test and the Range.Find method when needing something more bulletproof. I've seen the Range.Find method written including the argument: After:=Range("A1") to force the search to start from the last row / col of the worksheet, given that the SearchDirection is defined as xlPrevious. If the After:= argument is omitted, is there a default starting point.. maybe from the current location of the pointer? Just curious if it is needed and or makes a difference. Thanks again for all of your great videos. Always learn something fun and new :)) Thumbs up!!
@Excelmacromastery
@Excelmacromastery 3 жыл бұрын
Thanks Wayne. The default starting cell(i.e. After) is the Top Left cell of the range. If you are using the Excel Find Dialog then the default After cell is the active cell. See excelmacromastery.com/excel-vba-find/#Using_After_with_Find
@wayneedmondson1065
@wayneedmondson1065 3 жыл бұрын
@@Excelmacromastery Awesome! Thanks Paul :))
@HonStuartK
@HonStuartK 2 жыл бұрын
When I tried the "best" (i.e. the "find") solution it didn't work for my last column. My last column was W but it reported U. (V was empty). When I examined it I saw that some of the W cells were merged with X cells. When I un-merged W & X it worked. While I would understand if it had reported W or X, I'm not sure why the find method didn't report either of those columns and stopped at U instead. So this is certainly a drawback to that method.
@srider33
@srider33 3 жыл бұрын
To me, the major issue with xl(up/down) method is that it ignores hidden rows. I also use find -- the only draw back is that it messes with my settings the next time, but that's an acceptable penalty compared to all the others.
@davescott7680
@davescott7680 3 жыл бұрын
I just created a function that resets the settings. Problem solved.
@luapnagle
@luapnagle 2 жыл бұрын
wow, I'm 62 and just getting into VBA, not sure I'm getting into and EOL language. I looked at all your options and thought I should share one I use for selecting report print areas Is it simpler than your option ? It will fail with jagged data, correct ? 'Declare variables Dim startcell As Range Dim Lastrow As Long Dim lastcol As Long Dim sh As Worksheet 'Set objects Set startcell = Range("B2") Set WS = Sheets("data") 'Find last row and column with data Lastrow = WS.Cells(WS.Rows.Count, startcell.Column).End(xlUp).Row lastcol = WS.Cells(startcell.Row, WS.Columns.Count).End(xlToLeft).Column 'Select the dynamic range WS.Range(startcell, WS.Cells(Lastrow, lastcol)).Select
@thenebu
@thenebu 2 жыл бұрын
Great Video ! as always! Just can't download the Code, cause the site isnt loading. Update: it was my adblock. Your site ist now "excepted" :D
@muhammadhanifsoomro3166
@muhammadhanifsoomro3166 5 ай бұрын
Sir if data is long or short Lastrow how to automatically select lastrow when generated PDF report ۔۔so how does it's work ۔۔
@edwar368
@edwar368 2 жыл бұрын
You make a lot of mention of "Protected sheets", assuming you have some control over the actual workbook, you can protect the sheets via VBA and by doing that you have the option of using the UserInterfaceOnly:=True with the Protect method, which allows most VBA activity to run against protected sheets. If I control I workbook, I generally have a "ProtectSheets" macro that runs automatically when the workbook is opened, to apply this setting
@rrrraaaacccc80
@rrrraaaacccc80 10 ай бұрын
Great 💯👍
VBA Advanced Filter - The FASTEST way to Copy and Filter Data
18:33
Excel Macro Mastery
Рет қаралды 286 М.
How to Use Class Interfaces in Excel VBA
20:16
Excel Macro Mastery
Рет қаралды 82 М.
Beat Ronaldo, Win $1,000,000
22:45
MrBeast
Рет қаралды 154 МЛН
Арыстанның айқасы, Тәуіржанның шайқасы!
25:51
QosLike / ҚосЛайк / Косылайық
Рет қаралды 685 М.
The 3 Critical Data Scenarios Every VBA User Should Know
20:41
Excel Macro Mastery
Рет қаралды 9 М.
Watch these 28 minutes if you want to become an Advanced VBA user...
29:01
Excel Macro Mastery
Рет қаралды 56 М.
Python for VBA Developers in 30 Minutes
30:05
Excel Macro Mastery
Рет қаралды 16 М.
How to make your Excel VBA code run 1000 times faster
16:55
Excel Macro Mastery
Рет қаралды 364 М.
The Ultimate Guide to Copying Data using Excel VBA
31:05
Excel Macro Mastery
Рет қаралды 70 М.
Excel Macro Class 3 - Looping through Ranges & Working with Cells
31:16
Reduce VBA Errors by 90% (with this little-known Method)
16:59
Excel Macro Mastery
Рет қаралды 59 М.
5 Excel Secrets You'll Be Embarrassed You Didn't Know
17:32
Excel Campus - Jon
Рет қаралды 265 М.
Beat Ronaldo, Win $1,000,000
22:45
MrBeast
Рет қаралды 154 МЛН