excel - calculating loop didn't work vba -
i trying calculate range m13:m22
using conditional values , looping, of code works in cell m13
, doesn't loop cell m22
. how solve problem?
here code:
private sub commandbutton1_click() dim pelanggan range, alamat range, diskon range, jdiskon range, tanggal range, jtempo range dim rout(1 10) variant, long dim path string path = "\\faizal\data d faizal\daftar harga\price list" filename = dir(path & "database.xlsx") set pelanggan = range("e7") set alamat = range("e8") set diskon = range("l25") set tanggal = range("l7") set jdiskon = range("p13") set jtempo = range("k30") getalamat = application.worksheetfunction.vlookup(pelanggan & range("j7"), workbooks("database.xlsx").worksheets("db").range("a6:n1350"), 14, false) getdiskon = application.worksheetfunction.vlookup(pelanggan & range("j7"), workbooks("database.xlsx").worksheets("db").range("a6:n1350"), 6, false) getjdiskon = application.worksheetfunction.vlookup(pelanggan & range("j7"), workbooks("database.xlsx").worksheets("db").range("a6:n1350"), 11, false) getjtempo = application.worksheetfunction.vlookup(pelanggan & range("j7"), workbooks("database.xlsx").worksheets("db").range("a6:n1350"), 13, false) alamat.value = getalamat diskon.value = getdiskon / 100 jdiskon.value = getjdiskon tanggal.value = datevalue(now) jtempo.value = getjtempo 'here calculation won't go loop = 13 22 getharga = application.worksheetfunction.vlookup(range("d" & i) & range("e" & i), workbooks("database.xlsx").worksheets("gold").range("e4:h80"), 4, false) if jdiskon = "nett" range("m" & i).value = getharga - (getharga * diskon) range("l25").clearcontents elseif jdiskon = "pot" range("m" & i).value = getharga range("l25").value = diskon elseif jdiskon = "diskon kitir" range("m" & i).value = getharga range("l25").clearcontents end if next end sub
your question: "... code works in cell m13 , doesn't loop cell m22. how solve problem?"
your loop ok, not problem have solve. have debug find causes of loop not performing actions mean to.
i posting below modified code, 2 features: 1) qualifies range
s, avoid unexpected errors, may want check this; 2) uses msgbox
es, 1 way of debugging.
this pinpoint "error".
private sub commandbutton1_click() dim pelanggan range, alamat range, diskon range, jdiskon range, tanggal range, jtempo range dim rout(1 10) variant, long dim path string path = "\\faizal\data d faizal\daftar harga\price list" filename = dir(path & "database.xlsx") dim wb workbook, ws1 worksheet, ws2 worksheet, rng1 range set wb = workbooks("database.xlsx") set ws1 = wb.worksheets("db") set ws2 = wb.worksheets("gold") set rng1 = ws.range("a6:n1350") set pelanggan = ws1.range("e7") set alamat = ws1.range("e8") set diskon = ws1.range("l25") set tanggal = ws1.range("l7") set jdiskon = ws1.range("p13") set jtempo = ws1.range("k30") dim rng2 range set rng2 = ws1.range(pelanggan.value & ws1.range("j7").value) getalamat = application.worksheetfunction.vlookup(rng2, rng1, 14, false) getdiskon = application.worksheetfunction.vlookup(rng2, rng1, 6, false) getjdiskon = application.worksheetfunction.vlookup(rng2, rng1, 11, false) getjtempo = application.worksheetfunction.vlookup(rng2, rng1, 13, false) alamat.value = getalamat diskon.value = getdiskon / 100 jdiskon.value = getjdiskon tanggal.value = datevalue(now) jtempo.value = getjtempo 'here calculation won't go loop = 13 22 dim rng3 range set rng3 = ws1.range(ws1.range("d" & i).value & ws1.range("e" & i).value) getharga = application.worksheetfunction.vlookup(rng3, ws2.range("e4:h80"), 4, false) msgbox "getharga = " & getharga & " = " & if jdiskon = "nett" ws1.range("m" & i).value = getharga - (getharga * diskon) ws1.range("l25").clearcontents elseif jdiskon = "pot" ws1.range("m" & i).value = getharga ws1.range("l25").value = diskon elseif jdiskon = "diskon kitir" ws1.range("m" & i).value = getharga ws1.range("l25").clearcontents else msgbox "jdiskon = " & jdiskon & " = " & end if next end sub
(ps: not have system excel, code may need little adjustments).
Comments
Post a Comment