i had a worksheet in which i had a column Named Cheque No. i want to print the missing cheque no's in a series of cheque no's.The logic here is that there will be different series of cheque nos for different transactions.Just check out my worksheet.
i had a worksheet in which i had a column Named Cheque No. i want to print the missing cheque no's in a series of cheque no's.The logic here is that there will be different series of cheque nos for different transactions.Just check out my worksheet.
Using your posted workbook....here's something to try.
This regular formula returns a list of the missing check numbers:
Copy that formula down as far as you need.![]()
H2: =SMALL(INDEX(ISNA(MATCH(ROW(INDEX(D:D,MIN(D:D)-650000): INDEX(D:D,MAX(D:D)-650000))+650000,D:$D,0))*(ROW(INDEX(D:D,MIN(D:D)-650000): INDEX(D:D,MAX(D:D)-650000))),0),COUNT(D:D)+ROWS($1:1))+650000
Note: the 650000 adjustments are necessary because we are using Row Numbers
to simulate your series...and Excel 2003 only has 65,536 rows.
In your example, these values are returned in H2:H4
652001
652003
652004
Is that something you can work with?
how to do the same using vba
This will list the missing Checks in column J:
![]()
Option Explicit Sub ListCheckNums() Dim i, LastRow, LastNum As Long LastRow = Range("A" & Rows.Count).End(xlUp).Row LastNum = Range("D" & LastRow).Value Application.ScreenUpdating = False Range("J1").Value = "Missing Checks" Range("J2").Value = Range("D2").Value For i = 3 To LastNum Range("J" & i).Value = Range("J" & i - 1).Value + 1 If Range("J" & i).Value = LastNum Then Exit For Next i LastRow = Range("J" & Rows.Count).End(xlUp).Row Range("K2:K" & LastRow).FormulaR1C1 = "=COUNTIF(C4,RC[-1])" Range("J1").AutoFilter Range("J1").AutoFilter Field:=2, Criteria1:="0" Range("J3", Range("J3").End(xlDown)).Copy Range("L2") Range("J1").AutoFilter Range("J2:K" & LastRow).ClearContents Range("L2", Range("L2").End(xlDown)).Cut Range("J2") Application.ScreenUpdating = True End Sub
_________________
Microsoft MVP 2010 - Excel
Visit: Jerry Beaucaire's Excel Files & Macros
If you've been given good help, use theicon below to give reputation feedback, it is appreciated.
Always put your code between code tags. [CODE] your code here [/CODE]
?None of us is as good as all of us? - Ray Kroc
?Actually, I *am* a rocket scientist.? - JB (little ones count!)
By the way, can u tell me what this means:LastRow = Range("A" & Rows.Count).End(xlUp).Row
i think i counts the cells down the column like A1,A2,A3 am i correct
"Rows.Count" means "the last row in the entire workbook". This is different for different versions of Excel.
"Range("A" & Rows.Count)" means "the last cell in column A in the entire workbook..." In Excel 2003 that's A65536.
"Range("A" & Rows.Count).End(xlUp)" means "start at the last cell in column A and jump UP to the last cell with data in it.
LastRow = Range("A" & Rows.Count).End(xlUp).Row means "remember the ROW# of the last cell in column A with data in it and call it "LastRow" for short, usable as a variable in other VBA code.
===================
If that takes care of your need, be sure to EDIT your original post (Go Advanced) and mark the PREFIX box [SOLVED]
JB, re:
i & LastRow are Variants in the above, perhaps you meant ?![]()
Dim i, LastRow, LastNum As Long
![]()
Dim i As Long, LastRow As Long, LastNum As Long
My Recommended Reading:
Volatility
Sumproduct & Arrays
Pivot Intro
Email from XL - VBA & Outlook VBA
Function Dictionary & Function Translations
Dynamic Named Ranges
Someone recently indicated to me that:
...was shorthand for:![]()
Dim i, LastRow, LastNum As Long
Before that I had always used the latter, and as my formulas all continue to operate as expected when I used the shorthand, I surmised their suggestion was correct.![]()
Dim i As Long, LastRow As Long, LastNum As Long
Prior to that I had always thought that declaring JUST a variable name mean Variant, but this testing made me believe otherwise... (literally just days ago).
So I was right in my original understanding, I DO need to declare in longhand? Why would my numerical(s) variable continue to function with no issues? Usually I get error messages when I use the wrong TYPE of variable.
In VBA
only C is Long, a & b are Variants ... whereas in .NET a, b & c would all be Long![]()
Dim a, b, c As Long
As to why your code works ... VBA is designed for non-programmers ie there is the expectation that Variables may not be declared at all - hence Option Explicit is not default setting.
Anything not declared explicitly is assiged a Variant and a Variant can be anything hence the code works regardless...
General school of thought is: Variants = Inefficient/Expensive, however, I've heard MS MVP's say recently (Simon Hodge) that they think that's not really that significant an issue in VBA and that in reality all Cells are Variants (and there are lots of those without impacting performance!).
Note: In .NET, code is Option Explicit and the Variant type no longer exists (one must use Object)
Last edited by DonkeyOte; 04-25-2009 at 11:13 AM. Reason: typos
Its nice to see those replies regarding my little doubts.I feel that they are significant i building up the code.really, thanks for the good explanation to both of u.
I want to know the generalised formula(VBA SNIPPET) for using the code in any macro to check the last cell used /last cell in the column.Also do tell me what does & Mean.
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks