I have a routine that asks for non contiguous columns them copies those columns to a new work sheet. The problem I have run into is that the number of columns are not always the same. I have been using a user form that allows selection of cells that allow the column numbers to be passed to the union function. This is the static code
if one of the variables is missing the with loop fails. I. Just cannot figure out how to build the union dynamically. Any thoughts really appreciated.
Peter
Code:
[COLOR=#000000][FONT=UICTFontTextStyleTallBody]Public WellNameCol, ProdDatecol, ProdTypeCol, ProdPriceCol, GrossCol, ExpNameCol, ExpAmountCol, OwnNetCol[/FONT][/COLOR]
[COLOR=#000000][FONT=UICTFontTextStyleTallBody]Sub TestForm()[/FONT][/COLOR]
[COLOR=#000000][FONT=UICTFontTextStyleTallBody]Unload UserForm1[/FONT][/COLOR]
[COLOR=#000000][FONT=UICTFontTextStyleTallBody]sSheet = ActiveSheet.Name[/FONT][/COLOR]
[COLOR=#000000][FONT=UICTFontTextStyleTallBody]ActiveWorkbook.Sheets.Add[/FONT][/COLOR]
[COLOR=#000000][FONT=UICTFontTextStyleTallBody]ActiveSheet.Name = "ActiveColumns"[/FONT][/COLOR]
[COLOR=#000000][FONT=UICTFontTextStyleTallBody]With Worksheets(sSheet)[/FONT][/COLOR]
[COLOR=#000000][FONT=UICTFontTextStyleTallBody]Application.Union(.Columns(WellNameCol), .Columns(ProdDatecol), .Columns(ProdTypeCol), .Columns(ProdPriceCol), .Columns(GrossCol), .Columns(ExpNameCol), _[/FONT][/COLOR]
[COLOR=#000000][FONT=UICTFontTextStyleTallBody].Columns(ExpAmountCol), .Columns(OwnNetCol)).Copy Worksheets("Activecolumns").Range("A1")[/FONT][/COLOR]
[COLOR=#000000][FONT=UICTFontTextStyleTallBody]End With[/FONT][/COLOR]
if one of the variables is missing the with loop fails. I. Just cannot figure out how to build the union dynamically. Any thoughts really appreciated.
Peter