Trouble debugging a wrong data type error for a custom VBA function in excel 2010 -
i have been trying larn more excel (specifically how utilize vba well) , have been making simple rpg in excel.
i tried create relatively simple function running error can't seem identify. code doesn't seem have errors goal utilize function in excel's normal view , check if string equal strings in sheet.
basically, =checkmonster(a1) or that. however, whenever seek input it, type error.
function checkmonster(mon string) dim n integer n = 1 100 if mon = worksheets("monsterdatabase").cells(1, n).value activesheet.range("g2").value = worksheets("monsterdatabase").cells(2, n).value activesheet.range("g3").value = worksheets("monsterdatabase").cells(3, n).value activesheet.range("g4").value = worksheets("monsterdatabase").cells(4, n).value activesheet.range("g5").value = worksheets("monsterdatabase").cells(5, n).value else: mon = "" end if next end function ideally, if create alter given cell, numbers automatically update. however, wasn't sure how outside of brute forcing possible strings.
try this:
avoids loop finding string (i usedstrin) in single shot looking backwards range of involvement uses sub update cells not function (wont work have it) code
sub test() dim strin string strin = "fred" phone call updateme(strin) end sub sub updateme(byval strin) dim rng1 range dim ws worksheet set ws = sheets("monsterdatabase") set rng1 = ws.range("a1:cv1").find(strin, ws.[a1], xlvalues, xlwhole, xlbycolumns, xlprevious) if not rng1 nil activesheet.range("g2:g5").value = rng1.offset(1, 0).resize(4, 1).value end if end sub excel vba
No comments:
Post a Comment