I am brand new in VBA and learning on my own. I came up with a code that works but I know there must be a more elegant way to write this without using the Select
method.
wscount = ActiveWorkbook.Worksheets.Count
Sheets.Add After:=Sheets(Sheets.Count)
Worksheets(1).Select
Range("B2:B100").Copy
Worksheets(wscount + 1).Select
Range("A1:A100").Select
Selection.PasteSpecial Paste:=xlPasteColumnWidths
Selection.PasteSpecial Paste:=xlPasteAllUsingSourceTheme, Operation:=xlNone _
, SkipBlanks:=False, Transpose:=False
I wish I could get the width of the column set in the code instead of copied from the source.
Also, is there a way to have the width of the column to change based on the "longest" text in one cell of the range?
Anyway, my two questions are:
- how to write the above code without having to use
Select
, and - how to set the width of the column so I do not copy from the source.