excel - Use VBA to replace sporadic #N/A cells with a formula -
i have data comes different sources via data/connections goes sheet/table called rawdata. have created macro linked button user must click fill in of data in rawdata index/match function points workbook reservation number rawdata matched other workbook determine length of stay.
i not appending said workbook rawdata table different reasons. can go route if need figured there easier route before cross bridge. issue have once macro ran, other workbook, @ times, may not have reservation data. in these cases, had manually determine data.
this new data can placed within main workbook [but have in it's own workbook (losnaintoactuallos.xlsm) i've been running tests on making work]. , formula has pasted table because when table refreshes, row of data have length of stay removes formula , replaces it's original value, blank cell.
what need code loop through cells within f column of table, determine cells #n/a errors, paste formula in error cell. have done research , can't seem find suits needs. attempted doing loop seeing i'm still pretty new vba coding, it's not strong suit.
sub macro2() dim r integer lastrow = range("b" & rows.count).end(xlup).row worksheets("sheet1").range("f2:f" & lastrow) r = 2 lastrow if .iserror(worksheets("sheet1").range("f" & r)).value .formula = "index(losnaintoactuallos.xlsm!table1[#data],match([@reservation],losnaintoactuallos.xlsm!table1[reservation],0),7)" .value = .value end if next r end end sub
when run code if statement run-time error '438': object doesn't support property or method. if remove first period .iserror compile error: invalid qualifier.
iserror
not part of worksheets("sheet1").range("f2:f" & lastrow)
switch this.
sub macro2() dim r long dim lastrow long lastrow = worksheets("sheet1").range("b" & rows.count).end(xlup).row r = 2 lastrow worksheets("sheet1").range("f" & r) if iserror(.value) .formula = "index(losnaintoactuallos.xlsm!table1[#data],match([@reservation],losnaintoactuallos.xlsm!table1[reservation],0),7)" .value = .value end if end next r end sub
Comments
Post a Comment