vba - Copy Multiple Columns over by Column name -


i trying copy columns on worksheet going column name. problem below code copies on price calculator status column. overwriting other two. there better way have code modified appends rather overwrite?

dim acell1, acell2, acell3 range dim strsearch string

strsearch1 = "change request description" strsearch2 = "current state" strsearch3 = "price calculator status"  'set ws = thisworkbook.sheets(1)  wrkbk     set acell1 = sheets("3. pmo internal view").rows(1).find(what:=strsearch1, lookin:=xlvalues, _         lookat:=xlwhole, searchorder:=xlbyrows, searchdirection:=xlnext, _         matchcase:=false, searchformat:=false)     'sheets("3. pmo internal view").columns(acell.column).copy      set acell2 = sheets("3. pmo internal view").rows(1).find(what:=strsearch2, lookin:=xlvalues, _         lookat:=xlwhole, searchorder:=xlbyrows, searchdirection:=xlnext, _         matchcase:=false, searchformat:=false)      'sheets("3. pmo internal view").columns(acell.column).copy      set acell3 = sheets("3. pmo internal view").rows(1).find(what:=strsearch3, lookin:=xlvalues, _         lookat:=xlwhole, searchorder:=xlbyrows, searchdirection:=xlnext, _         matchcase:=false, searchformat:=false)      'if not acell nothing        ' msgbox "value found in cell " & acell.address & vbcrlf & _        ' "and column number " & acell.column          '~~> copying here         sheets("3. pmo internal view").columns(acell1.column).copy         sheets("3. pmo internal view").columns(acell2.column).copy         sheets("3. pmo internal view").columns(acell3.column).copy     'else         'msgbox "search value not found"     'end if end 

change copy lines to:

sheets("3. pmo internal view").range(sheets("3. pmo internal view").columns(acell1.column).address & "," & sheets("3. pmo internal view").columns(acell2.column).address & "," & sheets("3. pmo internal view").columns(acell3.column).address).copy 

this selects columns in 1 step, multiple areas range("a:a, c:c, e:e"). comma's text string additions, if use comma in range command has different meaning.


Comments

Popular posts from this blog

image - ClassNotFoundException when add a prebuilt apk into system.img in android -

I need to import mysql 5.1 to 5.5? -

Java, Hibernate, MySQL - store UTC date-time -