![]() |
Insert columns until a certain number has been reached
Hi all, I need help with inserting a variable number of columns. Heres the details: In one sheet I have 52 columns (this will always change) of data and in another I have 50 (again this will change). In the sheet with 50 I would like to insert X number of columns so both sheets have the same number. (52) I cannot just copy and paste as formulas I have written previously will be overwritten. I am fairly new to writing tihs type of code but heres what I have: Dim RawDataColCount As Integer Sheets("Raw Data").Select RawDataColCount = Cells.SpecialCells(xlCellTypeLastCell).Column Sheets("Data").Select Dim DataColCount As Integer DataColCount = Columns("B:AY").Count If RawDataColCount DataColCount Then Sheets("Data").Select Range("B:B").Select Selection.Insert Shift:=xlToRight Do Until DataColCount = RawDataColCount DataColCount = DataColCount + 1 Loop End If -- moglione1 ------------------------------------------------------------------------ moglione1's Profile: http://www.excelforum.com/member.php...o&userid=26414 View this thread: http://www.excelforum.com/showthread...hreadid=530422 |
Insert columns until a certain number has been reached
If RawDatacolcount Datacolcount Then
Range("B:B").Resize(, RawDatacolcount - Datacolcount).Select Selection.Insert Shift:=xlToRight End If This will insert n columns at a time HTH -- AP "moglione1" a écrit dans le message de ... Hi all, I need help with inserting a variable number of columns. Heres the details: In one sheet I have 52 columns (this will always change) of data and in another I have 50 (again this will change). In the sheet with 50 I would like to insert X number of columns so both sheets have the same number. (52) I cannot just copy and paste as formulas I have written previously will be overwritten. I am fairly new to writing tihs type of code but heres what I have: Dim RawDataColCount As Integer Sheets("Raw Data").Select RawDataColCount = Cells.SpecialCells(xlCellTypeLastCell).Column Sheets("Data").Select Dim DataColCount As Integer DataColCount = Columns("B:AY").Count If RawDataColCount DataColCount Then Sheets("Data").Select Range("B:B").Select Selection.Insert Shift:=xlToRight Do Until DataColCount = RawDataColCount DataColCount = DataColCount + 1 Loop End If -- moglione1 ------------------------------------------------------------------------ moglione1's Profile: http://www.excelforum.com/member.php...o&userid=26414 View this thread: http://www.excelforum.com/showthread...hreadid=530422 |
All times are GMT +1. The time now is 10:23 AM. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com