excel - Adding Column from a Range of Cells -


apologies if may seem duplicate, looking specific solution perhaps common problem.

i have following code add rows range of cells:

enter image description here

sub insert_matrix_rows()     dim lr integer, fr integer      fr = columns("b").find(what:="user r", after:=range("b9")).row 'searching row of "user r" header     lr = range("b" & fr).end(xldown).row 'searching last row in risk table      rows(lr + 1).insert shift:=xldown 'inserting new row    'cells(lr + 1, "b") = cells(lr, "b") + 1 'adding sequential number     rows(lr).copy 'copying format of last row     rows(lr + 1).pastespecial paste:=xlpasteformats 'pasting format new row     application.cutcopymode = false 'deactivating copy mode     cells(lr + 1, "c").select end sub 

i assign macro , works copy row 9, , paste below row. essentially, copy process columns instead. rows might produced code above included when producing columns, , vice versa.

i have attempted translate code work columns run errors (type mismatch):

  sub insert_matrix_columns()     dim lc integer, fc integer      fc = columns("d").find(what:="user c", after:=range("e6")).column 'searching row of "user c" header     lc = range("e" & fr).end(xlright).column 'searching last row in risk table      columns(lc + 1).insert shift:=xlright 'inserting new row    'cells(lr + 1, "b") = cells(lr, "b") + 1 'adding sequential number     columns(lc).copy 'copying format of last row     columns(lc + 1).pastespecial paste:=xlpasteformats 'pasting format new row     application.cutcopymode = false 'deactivating copy mode     cells(lc + 1, "e").select end sub 

replace

fc = columns("d").find(what:="user c", after:=range("e6")).column 

with

fc = rows(6).find(what:="user c", after:=range("e6")).column 

edit: here working code (i reproduced table) using:

sub insert_matrix_columns()     dim lastcol range      set lastcol = rows(6).find(what:="user c").end(xltoright).entirecolumn      columns(lastcol.column + 1).insert shift:=xlshifttoright     lastcol.copy     columns(lastcol.column + 1).pastespecial paste:=xlpasteformats      application.cutcopymode = false end sub 

main problem code using xlright instead of xlshifttoright , xltoright respectively -4152, -4161, -4161


Comments

Popular posts from this blog

php - Vagrant up error - Uncaught Reflection Exception: Class DOMDocument does not exist -

vue.js - Create hooks for automated testing -

Add new key value to json node in java -