D
Dow
I have a spreadsheet with columns labeled, for example, X1 X2 X3 X4 X5
X6 X7 X8 X9 X10. I need all 10 columns but where this data pulls from
only gives me the columns that have data in the rows below. So if
column X2 is blank it does not pull X2 and would give me X1 X3 X4 X5
X6 X7 X8 X9 X10.
I found this macro for when there is only 1 column missing:
Dim XLCell As Range
Set XLCell = Sheets("Test").Range("1:1").Find("X4", , xlValues,
xlWhole)
If XLCell Is Nothing Then Sheets("Test").Range
("B1").EntireColumn.Insert
Sheets("Test").Range("B1").Value = "X4"
I can run this 10 times as 10 seperate Subs changing X4 to X1 and then
X2 and etc. to make sure I have all of my columns.
I suspect there is a better way to do this. Does anyone know a macro
that will check row 1 for all of these values and then insert the
missing ones? The location that it inserts them in is not important
(it could even add them onto the end) because I will be sorting them
afterwards.
Thank you for the help,
Dow.
X6 X7 X8 X9 X10. I need all 10 columns but where this data pulls from
only gives me the columns that have data in the rows below. So if
column X2 is blank it does not pull X2 and would give me X1 X3 X4 X5
X6 X7 X8 X9 X10.
I found this macro for when there is only 1 column missing:
Dim XLCell As Range
Set XLCell = Sheets("Test").Range("1:1").Find("X4", , xlValues,
xlWhole)
If XLCell Is Nothing Then Sheets("Test").Range
("B1").EntireColumn.Insert
Sheets("Test").Range("B1").Value = "X4"
I can run this 10 times as 10 seperate Subs changing X4 to X1 and then
X2 and etc. to make sure I have all of my columns.
I suspect there is a better way to do this. Does anyone know a macro
that will check row 1 for all of these values and then insert the
missing ones? The location that it inserts them in is not important
(it could even add them onto the end) because I will be sorting them
afterwards.
Thank you for the help,
Dow.