excel - Why does `Empty` not work in this VBA code? -
the code below supposed check if cell empty and, if empty, paste contents of b26 cell. if cell not empty, moves on check cell below it. tried using isempty didn't work, figured excel defaulting empty cells 0. tried using empty(as shown in code below) doesn't work either.
sub part1_component_1_foam_color() ' ' transfers component 1 data if foam or color ' ' windows("transfer template.xlsm").activate range("b26").select selection.copy windows("protected_jd_form.xls").activate if range("b27:c27") = empty range("b27:c27").select selection.pastespecial paste:=xlpastevaluesandnumberformats, operation:= _ xlnone, skipblanks:=false, transpose:=false exit sub elseif range("b28:c28") = empty range("b28:c28").select selection.pastespecial paste:=xlpastevaluesandnumberformats, operation:= _ xlnone, skipblanks:=false, transpose:=false exit sub elseif range("b29:c29") = empty range("b29:c29").select selection.pastespecial paste:=xlpastevaluesandnumberformats, operation:= _ xlnone, skipblanks:=false, transpose:=false exit sub elseif range("b30:c30") = empty range("b30:c30").select selection.pastespecial paste:=xlpastevaluesandnumberformats, operation:= _ xlnone, skipblanks:=false, transpose:=false exit sub end if windows("transfer template.xlsm").activate range("a1").select end sub
you can use
if application.worksheetfunction.counta(range("b27:c27")) = 0 instead of
if range("b27:c27") = empty by way, there no need select range before pasting data.
this code
range("b27:c27").select selection.pastespecial paste:=xlpastevaluesandnumberformats, operation:= _ xlnone, skipblanks:=false, transpose:=false can replaced with
range("b27:c27").pastespecial paste:=xlpastevaluesandnumberformats, operation:= _ xlnone, skipblanks:=false, transpose:=false
Comments
Post a Comment