vba - Copy specific columns instead of entire column -


i have created following vba code:

sub x()  dim sht worksheet, summarysht worksheet dim rmin range, rmax range  each sht in worksheets    if not sht.name "summary*"         set summarysht = sheets.add(after:=sheets(sheets.count))     summarysht.name = "summary " & sht.name     sht.range("f15000:f20000")         set rmin = .find(what:=worksheetfunction.min(.cells), lookat:=xlwhole, lookin:=xlvalues)         set rmax = .entirecolumn.find(what:=worksheetfunction.max(.entirecolumn))         .parent.range(rmin, rmax).entirerow.copy summarysht.range("a2")     end end if 

now want macro not copy entire row columns "b" , "g".

could me adjusting code need, i´m sure not big deal suck @ vba thats why..

thank much!

i added new variable make code little more readable. code takes intersection of desired region columns b , g , combines them using union.

sub x()  dim sht worksheet, summarysht worksheet dim rmin range, rmax range, rout range  each sht in worksheets     if not sht.name "summary*"         set summarysht = sheets.add(after:=sheets(sheets.count))         summarysht.name = "summary " & sht.name         sht.range("f15000:f20000")             set rmin = .find(what:=worksheetfunction.min(.cells), lookat:=xlwhole, lookin:=xlvalues)             set rmax = .entirecolumn.find(what:=worksheetfunction.max(.entirecolumn))             set rout = .parent.range(rmin, rmax).entirerow             union(intersect(rout, sht.range("b:b")), intersect(rout, sht.range("g:g"))).copy summarysht.range("a2")         end     end if next sht  end sub 

Comments

Popular posts from this blog

javascript - Clear button on addentry page doesn't work -

c# - Selenium Authentication Popup preventing driver close or quit -

tensorflow when input_data MNIST_data , zlib.error: Error -3 while decompressing: invalid block type -