Compare list to a table and output new entries using excel VBA -
i'm total novice when comes vba , in need of assistance. in 1 sheet have table , in sheet (same workbook) have list changing daily , need update table accordingly i.e. add together and/or remove entries accordingly. ideas thought i'd start are:
1) need determine size of table/list since it's changing 2) shall create utilize of vlookup combined nested loops compare each cell of list each cell of table?
all feedback appreciated.
i answered question similar few days ago. here link in example, based on array. modify results.
yes, need determine lastly row of list examining. - getlastrow (see below) vloopup isn't efficient match, or index match. can utilize worksheetfunction.match skip first occurance or see if there matches.steps consider:
determine lastly row of list examining. - getlastrow (see below)
create array of original list
determine lastly row of sec list
perform loop each item on sec sheet against each item on first. - loop within loop, might want utilize match or something, although i'm not sure how much time beingness saved using worksheetfunction, work in background. it's still doing work , similar work can code.
create array unmatched items - using redim array set it's size 1 larger @ time.
add unmatched items original sheet. (see below)
most of same thing on , over. adding items array cycling through cells 1 @ time. checking see if 1 value = value. if so, match= true.. sort of thing. @ link see other example.
to this, utilize .cells, instead of .range. .cells(row#, col#) format perfect looping. have variable row# or column# , increment loop. it's same clicking downwards arrow on sheet. can define formulas string.
dim r long ' or integer although i've read long more efficient. r = 4 sheets("sheet1").cells(r, 3) = "hello there c4!" 'result = sheet1!c4 = hello there c4
example: run add together unmatched items original list. want add together ones not there.
private sub addtosheet() phone call getlastrow r = lastrow + 1 = 0 = 0 n sheets("sheet1").cells(r, 1) = unmatchedarray(i) r = r + 1 next end sub private sub getlastrow() ' checking range("a1:a65536") lastrow = sheets("sheet1").cells(65536, 1).end(xlup).row end sub
excel vba excel-vba
No comments:
Post a Comment