View Single Post
  #11   Report Post  
Posted to microsoft.public.excel.programming
[email protected] sbitaxi@gmail.com is offline
external usenet poster
 
Posts: 158
Default Don't add to range if row already exists


'first element is the header
'second element is the word to find
'could be multiple arrays--like with "registration fee"
HeaderAndWords = Array(Array("Event ID", "Tribute"), _
Array("Donation status", "Cash pending"), _
Array("Registration fee", "waived"), _
Array("Registration fee", "cancelled"))


How does VBA differentiate between the header and the word to find?
I'm not sure I understand how LBound and UBound relate to these
arrays. Thinking it through -

LBound is the header, UBound is the "word to find", correct? Since
each array only has two values, hCtr will only have two iterations of
the For/Next, one for each value in each array, although the find may
located many rows.

What does the zero do in this line? Wait, that's the LBound value, so
it finds the Header cell and can be declared as the header that way,
while the 1 later calls the UBound value to find the "word to find."
Set FoundCell = .Cells.Find(What:=HeaderAndWords(hCtr)(0)


Some of my Finds/Deletes require further verification on values - If
the Registration Fee is Waived, but there is a payment recorded in the
payment column, then we need to keep this record. Would it be possible
to have a third value in the array which is the equation?
So the array would look something like -

Array("Registration fee", "cancelled", "If Intersect(Rows(MyCell.Row),
Columns(PaymentAmt.Column)).Value = 0 Then")

How can I convert that to a usable If statement rather than it being
stored as text? Would that be UBound(HeaderAndWords, 2) to retrieve
it?

In order to call that statement, is it possible to verify in the array
if there is a 2? Essentially -
if HCtr = LBound(HandW, 1) to UBound(HaW, 2) Then
UBound(HaW, 2)
------ insert delete range lines

In fact, I think most of my criteria has a second validation step
before the range gets added to the DelRng.

With wks
For hCtr = LBound(HeaderAndWords, 1) To UBound(HeaderAndWords, 1)
With .Rows(1) 'the header row
Set FoundCell = .Cells.Find(What:=HeaderAndWords(hCtr)(0), _
After:=.Cells(.Cells.Count), _
LookIn:=xlFormulas, _
LookAt:=xlWhole, _
SearchOrder:=xlByColumns, _
SearchDirection:=xlNext, _
MatchCase:=False, _
SearchFormat:=False)
End With



So this line tells Excel to delete the entire row, but for only one
of the columns?

Intersect(DelRng.EntireRow, .Columns(1)).EntireRow.Select 'Delete



Thank you Dave, this is a crash course in VBA and I know I have not
even scratched the surface.