vba - Excel not transferring data properly from one sheet to another -


recently i've been working on spreadsheet allows users input data on invoice template page, , save information on sheet. invoice template looks this: invoice box

i put in random inputs each cell. data here b17:h37 needs moved sheet named invoice data when "save" forum button pressed user. data supposed inputted d:g on invoice data page, result such: invoice data

a:c filled in different values outside b17:h37 (as shown in code below), but "name" data (column b) invoice box copied invoice data sheet while "hours", "cost", , "total" neglected. here's code have far (from tutorial found online):

sub save_invoice()   dim rng range   dim long   dim long   dim rng_dest range   application.screenupdating = false   'check if invoice # found on sheet "invoice data"   = 1   until sheets("invoice data").range("a" & i).value = ""     if sheets("invoice data").range("a" & i).value = sheets("invoice").range("e7") & "-" & range("f7").value       'ask overwrite invoice #?       if msgbox("overwrite invoice data?", vbyesno) = vbno         exit sub       else         exit       end if     end if     = + 1   loop   = 1   set rng_dest = sheets("invoice data").range("d:f")   'delete rows if invoice # found   until sheets("invoice data").range("a" & i).value = ""     if sheets("invoice data").range("a" & i).value = sheets("invoice").range("e7") & "-" & range("f7").value       sheets("invoice data").range("a" & i).entirerow.delete       = 1     end if     = + 1   loop   ' find first empty row in columns d:g on sheet invoice data   until worksheetfunction.counta(rng_dest.rows(i)) = 0     = + 1   loop   'copy range b17:f37 on sheet invoice   set rng = sheets("invoice").range("b17:h37")   ' copy rows containing values sheet invoice data  = 1 rng.rows.count     if worksheetfunction.counta(rng.rows(a)) <> 0       rng_dest.rows(i).value = rng.rows(a).value       'copy invoice number       sheets("invoice data").range("a" & i).value = sheets("invoice").range("e7") & "-" & range("f7").value       'copy date       sheets("invoice data").range("b" & i).value = sheets("invoice").range("b2").value       'copy project name       sheets("invoice data").range("c" & i).value = sheets("invoice").range("c7").value       = + 1     end if   next   application.screenupdating = true end sub 

i'm still new vba utterly confused. tried debug function , code screws up: for = 1 rng.rows.count if worksheetfunction.counta(rng.rows(a)) <> 0 rng_dest.rows(i).value = rng.rows(a).value . if me fix problem, appreciate much:)

also, side note, there way make rows "0"s in "total"(column h) not transferred invoice data page? thank time. new invoice page

in picture want row 7 , below deleted because didn't input in invoice page rows.

i modified result loop follow:

'copy rows containing values sheet invoice data = 17 37      if worksheetfunction.counta(sheets("invoice").range("b" & & ":h" & a)) <> 0          'copy invoice number         sheets("invoice data").range("a" & i) = sheets("invoice").range("e7") & "-" & sheets("invoice").range("f7")          'copy date         sheets("invoice data").range("b" & i) = sheets("invoice").range("b2")          'copy project name         sheets("invoice data").range("c" & i) = sheets("invoice").range("c7")          'copy name         sheets("invoice data").range("d" & i) = sheets("invoice").range("b" & a)          'copy hours         sheets("invoice data").range("e" & i) = sheets("invoice").range("f" & a)          'copy cost         sheets("invoice data").range("f" & i) = sheets("invoice").range("g" & a)          'copy total         sheets("invoice data").range("g" & i) = sheets("invoice").range("h" & a)          'increase invoice data row         = + 1      end if  next 

i tested code input data. work me. try this.

added:

if want add new condition, modify if statement follow:

if worksheetfunction.counta(sheets("invoice").range("b" & & ":g" & a)) <> 0  , sheets("invoice").range("h" & a) > 0 

Comments

Popular posts from this blog

dns - How To Use Custom Nameserver On Free Cloudflare? -

python - Pygame screen.blit not working -

c# - Web API response xml language -