 <hr> Before you read any further, you should read @paulag 's post on the Excel Online Summit. Then take a little time to watch day 1's presentations. https://steemit.com/steem/@paulag/promoting-steem-at-the-excel-online-summit-how-do-you-think-i-did Especially her presentation. Once she starts to merge blockchain with Excel Learning, the host's mind is blown. <hr> Back in around 2013, I was frustrated with vlookup function. It was very close to what I wanted, but there were a couple things that bothered me about the function. I was fluent in the Match/Index/Offset functions and their method of duplicating the capabilities of vlookup, but I wanted to share this with folks at work who weren't as comfortable. As the folks in the Excel Online Summit pointed out, always try to use the built in functions first before you break into the VBA. <hr> I tried to keep the "look and feel" of the function similar to vlookup, so it would be reasonably simple for folks to switch between the two. These are the parameters that I included in the formula: - the value you are searching for - the range you are searching in - the column within the range that you want to search (does not need to be the leftmost column) - the column within the range that you want to return - do you want to treat numbers and strings the same (so 1 equals "1") - if no match is found, what would you like to return - do you want to search for more than one match - if there are more than one match, what will delimit the results (before dynamic arrays ;-) ) I apologize in advance for the lack of comments in the code. ``` Function vlookup2(lookup_value As Variant, table_array As Range, column_to_search As Integer, column_to_return As Integer, _ Optional treat_numbers_as_string As Boolean = False, _ Optional result_if_not_found As String = "Not Found", _ Optional search_for_multiples As Boolean = False, _ Optional delim_if_multiples As String = "||") As String Dim rTemp As Range, bFound As Boolean, sResult As String, sSearchString As String Dim iFoundCount As Integer bFound = False iFoundCount = 0 sResult = "" If treat_numbers_as_string Then For Each rTemp In table_array.Rows If CStr(rTemp.Cells(1, column_to_search).Value) = CStr(lookup_value) Then If Not search_for_multiples Then sResult = rTemp.Cells(1, column_to_return).Value bFound = True Exit For Else sResult = sResult & delim_if_multiples & rTemp.Cells(1, column_to_return).Value bFound = True iFoundCount = iFoundCount + 1 End If End If Next rTemp Else For Each rTemp In table_array.Rows If rTemp.Cells(1, column_to_search).Value = lookup_value Then If Not search_for_multiples Then sResult = rTemp.Cells(1, column_to_return).Value bFound = True Exit For Else sResult = sResult & delim_if_multiples & rTemp.Cells(1, column_to_return).Value bFound = True iFoundCount = iFoundCount + 1 End If End If Next rTemp End If If bFound Then Select Case iFoundCount Case 0 vlookup2 = sResult Case 1 vlookup2 = Mid(sResult, 2) Case Else vlookup2 = CStr(iFoundCount) & " found" & sResult End Select Else vlookup2 = result_if_not_found End If End Function ``` </p> For an example, here is some dummy data.  NOTE: grape and pear both have a 1, but for grape, it was entered as a string. Here are the results:  Based on the following general equation:  <hr> I hope you find this useful, or that it give you some ideas for a script of your own.
author | gikitiki |
---|---|
permlink | xlookup-almost-has-everything-i-need |
category | hive-102332 |
json_metadata | {"tags":["excel","vba","vlookup"],"users":["paulag"],"image":["https://cdn.steemitimages.com/DQmSVvLR5W7SiYqcRQSEfAJmSbomcnmVdYPKiCYxBnuQYGG/XLVBA.gif","https://cdn.steemitimages.com/DQmd7yw4gwDFKTx2238sPEiFynDajzpVLtwdihv8YF29pBn/image.png","https://cdn.steemitimages.com/DQmZnP5WYBWmiDqKG7sQYst62g3CPUimVEg4wnS15zEdMvt/image.png","https://cdn.steemitimages.com/DQmSTBsY1sBFLDGmTZRRLmAFvfiXYFAfzUrwzYQ3K85TEr4/image.png"],"links":["https://steemit.com/steem/@paulag/promoting-steem-at-the-excel-online-summit-how-do-you-think-i-did"],"app":"steemit/0.2","format":"markdown"} |
created | 2019-12-17 20:47:48 |
last_update | 2019-12-17 20:47:48 |
depth | 0 |
children | 5 |
last_payout | 2019-12-24 20:47:48 |
cashout_time | 1969-12-31 23:59:59 |
total_payout_value | 2.396 HBD |
curator_payout_value | 2.385 HBD |
pending_payout_value | 0.000 HBD |
promoted | 0.000 HBD |
body_length | 4,473 |
author_reputation | 16,572,681,158,525 |
root_title | "XLookup almost has everything I need" |
beneficiaries | [] |
max_accepted_payout | 1,000,000.000 HBD |
percent_hbd | 10,000 |
post_id | 93,502,667 |
net_rshares | 17,046,235,803,351 |
author_curate_reward | "" |
voter | weight | wgt% | rshares | pct | time |
---|---|---|---|---|---|
barrie | 0 | 0 | 5.5% | ||
pharesim | 0 | 1,296,454,227,926 | 11% | ||
tombstone | 0 | 769,072,701,824 | 2.75% | ||
boombastic | 0 | 573,945,640 | 5.5% | ||
matt-a | 0 | 95,134,236,526 | 4% | ||
redpalestino | 0 | 790,448,503,350 | 11% | ||
gikitiki | 0 | 2,000,138,431 | 5.5% | ||
meesterboom | 0 | 930,568,846,020 | 42% | ||
sazbird | 0 | 33,003,301,459 | 21% | ||
shaka | 0 | 193,336,419,054 | 2.75% | ||
wisbeech | 0 | 3,344,080,077 | 42% | ||
shadowspub | 0 | 1,111,647,407 | 1.38% | ||
uwelang | 0 | 13,647,776,885 | 1.37% | ||
petrvl | 0 | 15,401,798,423 | 2.2% | ||
dexter-k | 0 | 5,394,418,333 | 2.75% | ||
anomaly | 0 | 130,073,363 | 1% | ||
ansharphoto | 0 | 7,456,309,793 | 5.5% | ||
bmwrider | 0 | 61,965,249,829 | 100% | ||
vannour | 0 | 621,754,610 | 0.68% | ||
ethandsmith | 0 | 12,574,515,320 | 2.75% | ||
shafay | 0 | 1,102,565,528 | 5.5% | ||
shaunmza | 0 | 3,866,689,801 | 11% | ||
tarazkp | 0 | 1,961,862,462,381 | 88% | ||
azzurra92 | 0 | 867,748,546 | 5.5% | ||
elevator09 | 0 | 10,862,758,660 | 4.95% | ||
sarasate | 0 | 5,487,163,115 | 5.5% | ||
tyzzzz | 0 | 0 | 5.5% | ||
sokha | 0 | 679,877,289 | 5.5% | ||
vannfrik | 0 | 6,062,217,270 | 4.4% | ||
spoylerbg | 0 | 947,364,933 | 5.5% | ||
robi | 0 | 2,304,577,806 | 5.5% | ||
jagged | 0 | 11,841,520,813 | 5.5% | ||
roomservice | 0 | 71,679,230,836 | 5.5% | ||
sustainablyyours | 0 | 832,947,258 | 2.75% | ||
belahejna | 0 | 2,606,868,527 | 2.2% | ||
idas4you | 0 | 2,547,934,893 | 5.5% | ||
paulag | 0 | 1,034,387,555,673 | 100% | ||
insteem | 0 | 944,509,864 | 5.5% | ||
gunthertopp | 0 | 119,866,910,285 | 2.75% | ||
lupo | 0 | 1,434,306,943 | 5.5% | ||
m31 | 0 | 390,958,173,971 | 50% | ||
ccoin | 0 | 11,292,764,938 | 5.5% | ||
r3ap3r | 0 | 3,881,881,930 | 5.5% | ||
podnikatel | 0 | 267,471,773 | 0.55% | ||
sunisa | 0 | 1,414,571,919 | 3.85% | ||
djlethalskillz | 0 | 25,584,872,452 | 20% | ||
frikitiki | 0 | 1,216,613,693 | 100% | ||
niallon11 | 0 | 53,512,850,711 | 100% | ||
therealwolf | 0 | 832,983,851,094 | 5.5% | ||
szabolcs | 0 | 1,953,919,167 | 5.5% | ||
upme | 0 | 6,586,657,444 | 5.5% | ||
backtomining | 0 | 1,706,072,109 | 2.2% | ||
blockbrothers | 0 | 1,261,635,364,064 | 44% | ||
emrebeyler | 0 | 27,583,211,217 | 8.25% | ||
sagarthukral | 0 | 763,244,133 | 5.5% | ||
smartsteem | 0 | 1,491,644,869,983 | 5.5% | ||
mytechtrail | 0 | 44,009,596,805 | 25% | ||
b00m | 0 | 42,898,043,230 | 21% | ||
bebeomega | 0 | 141,047,752 | 5.5% | ||
loler555 | 0 | 521,291,352 | 2.75% | ||
obvious | 0 | 4,932,373,659 | 2.75% | ||
iqbaladan | 0 | 473,531,844 | 5.5% | ||
zainejj | 0 | 119,533,068 | 5.5% | ||
rombtc | 0 | 307,249,394 | 2.75% | ||
zipsardinia | 0 | 1,270,537,607 | 5.5% | ||
sco | 0 | 6,381,975,426 | 6.6% | ||
spiritualmax | 0 | 6,312,686,437 | 5.5% | ||
smartmarket | 0 | 24,915,340,942 | 5.5% | ||
errajesh | 0 | 1,682,070,696 | 5.5% | ||
lemony-cricket | 0 | 18,902,279,857 | 5.5% | ||
nedy | 0 | 3,385,420,547 | 5.5% | ||
blervin | 0 | 13,122,647,569 | 11% | ||
irgendwo | 0 | 5,055,397,091 | 7.7% | ||
alexandersteemit | 0 | 1,981,019,110 | 5.5% | ||
layra | 0 | 1,293,623,564 | 5.5% | ||
maikuraki | 0 | 651,426,051 | 5.5% | ||
lordjames | 0 | 4,799,021,776 | 2.75% | ||
kyuubi | 0 | 6,819,999,529 | 5.5% | ||
azircon | 0 | 783,866,182,034 | 10.45% | ||
ronaldoavelino | 0 | 8,451,261,552 | 1% | ||
thevote | 0 | 117,067,464,403 | 3.63% | ||
ajanphoto | 0 | 976,433,282 | 5.5% | ||
tijntje | 0 | 809,626,716 | 5.5% | ||
minerthreat | 0 | 18,502,628,278 | 5.5% | ||
aro.steem | 0 | 109,622,739 | 1.1% | ||
steemjet | 0 | 19,935,377,463 | 2.75% | ||
mikemoi | 0 | 4,071,341,250 | 5.5% | ||
stay4true | 0 | 35,889,537 | 5.5% | ||
justinmullet | 0 | 894,812,331 | 5.5% | ||
sky.nikolas20 | 0 | 852,002,173 | 5.5% | ||
mrnightmare89 | 0 | 157,122,299 | 0.55% | ||
xmrking | 0 | 1,842,914,311 | 5.5% | ||
jcbit | 0 | 26,901,897,398 | 5.5% | ||
deathcross | 0 | 179,257,305,753 | 100% | ||
spoke | 0 | 18,268,131,628 | 8.8% | ||
theexcelclub | 0 | 271,268,132,895 | 100% | ||
drfk | 0 | 3,514,615,220 | 2.75% | ||
laissez-faire | 0 | 58,860,486 | 100% | ||
cultus-forex | 0 | 3,459,809,486 | 3.3% | ||
macoolette | 0 | 27,845,497,421 | 3.3% | ||
steemjetmedia | 0 | 18,287,753,911 | 5.5% | ||
milky-concrete | 0 | 34,633,900,007 | 11% | ||
crypt0renegade | 0 | 5,723,048,004 | 5.5% | ||
edgarare1 | 0 | 7,064,417,080 | 5.5% | ||
bluerobo | 0 | 31,736,998,876 | 100% | ||
bluesniper | 0 | 62,118,653,878 | 25% | ||
steemtank | 0 | 6,302,208,426 | 5.5% | ||
wolfinator | 0 | 1,515,464,752 | 5.5% | ||
princessamber | 0 | 925,348,206 | 50% | ||
circa | 0 | 23,798,297,677 | 5% | ||
ghostdylan | 0 | 929,019,216 | 50% | ||
darrenfj | 0 | 46,875,793,727 | 25% | ||
andresurrego | 0 | 2,538,286,868 | 5.5% | ||
elizabethharvey | 0 | 1,083,264,444 | 5.5% | ||
steemdapps | 0 | 6,376,133,682 | 5.5% | ||
simply-happy | 0 | 2,248,541,849 | 4.95% | ||
kharma.scribbles | 0 | 0 | 0.69% | ||
aaronkroeblinger | 0 | 588,314,336 | 5.5% | ||
lefty619 | 0 | 0 | 5.5% | ||
epicdice | 0 | 46,925,815,291 | 3.3% | ||
thecryptohoarder | 0 | 14,115,267,711 | 20% | ||
bigmoneyman | 0 | 1,478,497,380 | 44% | ||
raspibot | 0 | 844,592,396 | 100% | ||
myotherstuff | 0 | 2,184,014,435 | 100% | ||
babytarazkp | 0 | 3,096,811,551 | 50% | ||
shtup | 0 | 826,196,646 | 5.5% | ||
curangel | 0 | 3,422,058,875,340 | 11% | ||
lass3 | 0 | 1,046,267,361 | 5.5% | ||
ctl001 | 0 | 588,548,163 | 100% | ||
joshmania | 0 | 26,185,449,327 | 7.92% | ||
antiretroviral | 0 | 956,647,116 | 5.5% | ||
harpun | 0 | 8,705,697,800 | 11% | ||
kryptoformator | 0 | 955,443,836 | 1.1% | ||
crustim | 0 | -9,223,176 | -10% | ||
sliponaz | 0 | -3,130,015 | -10% | ||
excelguy | 0 | 0 | 100% | ||
diazkongming | 0 | 0 | 100% |
Thats really impressive. I like how the code can return an array. So I have a big confession, I don't know VBA. I do know DAX and a bit of M, which are new languages used in Excel. but I never learned VBA. Now following, I know I will learn some neat tricks from you :-)
author | paulag |
---|---|
permlink | q2ogr3 |
category | hive-102332 |
json_metadata | {"app":"steemit/0.1"} |
created | 2019-12-17 22:21:03 |
last_update | 2019-12-17 22:21:03 |
depth | 1 |
children | 4 |
last_payout | 2019-12-24 22:21:03 |
cashout_time | 1969-12-31 23:59:59 |
total_payout_value | 0.000 HBD |
curator_payout_value | 0.000 HBD |
pending_payout_value | 0.000 HBD |
promoted | 0.000 HBD |
body_length | 275 |
author_reputation | 274,264,287,951,003 |
root_title | "XLookup almost has everything I need" |
beneficiaries | [] |
max_accepted_payout | 1,000,000.000 HBD |
percent_hbd | 10,000 |
post_id | 93,504,374 |
net_rshares | 3,639,207,575 |
author_curate_reward | "" |
voter | weight | wgt% | rshares | pct | time |
---|---|---|---|---|---|
gikitiki | 0 | 3,639,207,575 | 10% | ||
excelguy | 0 | 0 | 100% |
Honestly the best way to learn VBA is to record some macros and review how Excel codes the actions, since VBA is an Object-oriented, event-based language. The way I build Excel subs is somewhat the same everytime; start with the process you want to automate and the end-goal and have VBA conduct the necessary actions to complete that action: "Take this data and put it here", "Count this column or number of rows and return this value". Learning the procedure conventions and best-practices is the main topic to learn and you will pick up the different objects and events as you get more experience. I've got some great VBA examples on my site if you'd like to check them out. But I'm the opposite, I'm beginning to learn DAX and M!
author | excelguy |
---|---|
permlink | q3qtji |
category | hive-102332 |
json_metadata | {"app":"steemit/0.2"} |
created | 2020-01-07 15:26:06 |
last_update | 2020-01-07 15:26:06 |
depth | 2 |
children | 1 |
last_payout | 2020-01-14 15:26:06 |
cashout_time | 1969-12-31 23:59:59 |
total_payout_value | 0.112 HBD |
curator_payout_value | 0.112 HBD |
pending_payout_value | 0.000 HBD |
promoted | 0.000 HBD |
body_length | 735 |
author_reputation | 38,663,423,477 |
root_title | "XLookup almost has everything I need" |
beneficiaries | [] |
max_accepted_payout | 1,000,000.000 HBD |
percent_hbd | 10,000 |
post_id | 94,148,321 |
net_rshares | 1,231,065,223,078 |
author_curate_reward | "" |
voter | weight | wgt% | rshares | pct | time |
---|---|---|---|---|---|
paulag | 0 | 972,673,942,430 | 100% | ||
theexcelclub | 0 | 258,391,280,648 | 100% |
DAX and M rock. I don't know VBA ( and want to find the time to learn it) but I do know DAX and a little M. M and power query can remove the need for many VBA automation tasks, but it can not do everything VBA can do
author | paulag |
---|---|
permlink | q3qtuv |
category | hive-102332 |
json_metadata | {"app":"steemit/0.2"} |
created | 2020-01-07 15:32:57 |
last_update | 2020-01-07 15:32:57 |
depth | 3 |
children | 0 |
last_payout | 2020-01-14 15:32:57 |
cashout_time | 1969-12-31 23:59:59 |
total_payout_value | 0.000 HBD |
curator_payout_value | 0.000 HBD |
pending_payout_value | 0.000 HBD |
promoted | 0.000 HBD |
body_length | 219 |
author_reputation | 274,264,287,951,003 |
root_title | "XLookup almost has everything I need" |
beneficiaries | [] |
max_accepted_payout | 1,000,000.000 HBD |
percent_hbd | 10,000 |
post_id | 94,148,680 |
net_rshares | 0 |
In that case, itβs time for some basic VBA exercises.
author | gikitiki |
---|---|
permlink | q2ou38 |
category | hive-102332 |
json_metadata | {"app":"steemit/0.1"} |
created | 2019-12-18 03:09:09 |
last_update | 2019-12-18 03:09:09 |
depth | 2 |
children | 0 |
last_payout | 2019-12-25 03:09:09 |
cashout_time | 1969-12-31 23:59:59 |
total_payout_value | 0.000 HBD |
curator_payout_value | 0.000 HBD |
pending_payout_value | 0.000 HBD |
promoted | 0.000 HBD |
body_length | 53 |
author_reputation | 16,572,681,158,525 |
root_title | "XLookup almost has everything I need" |
beneficiaries | [] |
max_accepted_payout | 1,000,000.000 HBD |
percent_hbd | 10,000 |
post_id | 93,509,875 |
net_rshares | 0 |
Here's the first step... https://steemit.com/hive-102332/@gikitiki/excel-how-to-open-the-vba-editor
author | gikitiki |
---|---|
permlink | q2rrtx |
category | hive-102332 |
json_metadata | {"links":["https://steemit.com/hive-102332/@gikitiki/excel-how-to-open-the-vba-editor"],"app":"steemit/0.2"} |
created | 2019-12-19 17:13:09 |
last_update | 2019-12-19 17:13:09 |
depth | 2 |
children | 0 |
last_payout | 2019-12-26 17:13:09 |
cashout_time | 1969-12-31 23:59:59 |
total_payout_value | 0.000 HBD |
curator_payout_value | 0.000 HBD |
pending_payout_value | 0.000 HBD |
promoted | 0.000 HBD |
body_length | 100 |
author_reputation | 16,572,681,158,525 |
root_title | "XLookup almost has everything I need" |
beneficiaries | [] |
max_accepted_payout | 1,000,000.000 HBD |
percent_hbd | 10,000 |
post_id | 93,558,414 |
net_rshares | 0 |