Writing a VLOOKUP function in vba
Have you tried: Dim result As String Dim sheet As Worksheet Set sheet = ActiveWorkbook.Sheets(“Data”) result = Application.WorksheetFunction.VLookup(sheet.Range(“AN2”), sheet.Range(“AA9:AF20”), 5, False)
Have you tried: Dim result As String Dim sheet As Worksheet Set sheet = ActiveWorkbook.Sheets(“Data”) result = Application.WorksheetFunction.VLookup(sheet.Range(“AN2”), sheet.Range(“AA9:AF20”), 5, False)
According to the Apache POI Quick Guide, the POIFSFileSystem (or similarly, NPOIFSFileSystem) is only used with .xls (Excel versions through 2003) documents. The equivalent for .xlsx documents (Excel 2007+) is OPCPackage. OPCPackage pkg = OPCPackage.open(new File(“file.xlsx”)); You can create an XSSFWorkbook from the OPCPackage: XSSFWorkbook wb = new XSSFWorkbook(pkg); Or you can just create it … Read more
Actually a more refined solution is use the build-in function sumif, this function does exactly what you need, will only sum those expenses of a specified month. example =SUMIF(A2:A100,”=January”,B2:B100)
The advantage of using classes instead of just subroutines is that classes create a level of abstraction that allow you to write cleaner code. Admittedly, if you’ve never used classes before in VBA, there is a learning curve, but I believe it’s certainly worth the time to figure it out. One key indication that you … Read more
I believe you want to find the current region of A1 and surrounding cells – not necessarily all cells on the sheet. If so – simply use… Range(“A1”).CurrentRegion
I’m sure you’ll get a ton of “don’t do this” answers, and I must say, there is good reason. This isn’t an ideal solution…. That being said, I’ve gone down this road (and similar ones) before, mostly because the job specified it as a hard requirement and I couldn’t talk around it. Here are a … Read more
To put the same text in a certain number of cells do the following: Highlight the cells you want to put text into Type into the cell you’re currently in the data you want to be repeated Hold Crtl and press ‘return’ You will find that all the highlighted cells now have the same data … Read more
After more than one hour looking I found the answer: xlApp.DisplayAlerts = false; worksheet.Delete(); xlApp.DisplayAlerts = true;
You can use DateValue to convert your string to a date in this instance Dim c As Range For Each c In ActiveSheet.UsedRange.columns(“A”).Cells c.Value = DateValue(c.Value) Next c It can convert yyyy-mm-dd format string directly into a native Excel date value.
There is a way to make it more pythonic (works with three or more letters and uses less magic numbers): def col2num(col): num = 0 for c in col: if c in string.ascii_letters: num = num * 26 + (ord(c.upper()) – ord(‘A’)) + 1 return num And as a one-liner using reduce (does not check … Read more