SBendBuckeye
Programmer
I have used Access pretty extensively so am pretty familiar with VBA. I am doing much more Excel related work on my current project still using Access as an automation server.
My users have a standard Excel template that they use to request changes for a non Microsoft process. Valid columns have column names such as Name, Dept, Part#, etc. As part of the prevalidation of the Excel, I want to delete empty columns (eg no changes to data in this column).
I have created an Array of ColumnNames and want to spin through it one column at a time and delete those columns that only have 1 item in the column (the Column Name). I have already calculated the last row using SpecialCells to get it, so my code looks like this:
Dim rng As Range
Dim cl As Object
For lngCol = 1 To UBound(avarColumnNames)
'Define a range object for current column portion
Set rng = Range(Cells(1, lngCol), Cells(lngRow, lngCol)
'Get blank cells for the current range
rng.SpecialCells (xlCellTypeBlanks)
Next lngCol
A. Where do I find the cell count for the rng.SpecialCells statement? If it is equal to the number of rows in the column - 1 then the users entered not data into that column and it should be deleted. I think I am on the right track but something is missing. Can someone help me on this?
B. What is the best way to delete a column if it is not necessary? Is there a Columns collection somewhere in the worksheet item I can reference?
C. Previous to the above, I want to copy Sheet1 to Sheet2 and then if changes are made, I will rename Sheet2 to Original Sheet. How is the best way to do this in VBA. If I don't make changes how do I delete Sheet2?
D. I am used to spinning collections in Forms, QueryDefs, TableDefs, etc in Access. What are the major collections when working with Excel?
E. Is there an Office equivalent of Access Developers Handbook?
I'm sorry if the answers to these are obvious, but I remember beating my head against the wall with the same types of things learning Access and I would like to spare myself some pain if I can.
Thanks in advance for any help and/or suggestions!
Have a great day!
My users have a standard Excel template that they use to request changes for a non Microsoft process. Valid columns have column names such as Name, Dept, Part#, etc. As part of the prevalidation of the Excel, I want to delete empty columns (eg no changes to data in this column).
I have created an Array of ColumnNames and want to spin through it one column at a time and delete those columns that only have 1 item in the column (the Column Name). I have already calculated the last row using SpecialCells to get it, so my code looks like this:
Dim rng As Range
Dim cl As Object
For lngCol = 1 To UBound(avarColumnNames)
'Define a range object for current column portion
Set rng = Range(Cells(1, lngCol), Cells(lngRow, lngCol)
'Get blank cells for the current range
rng.SpecialCells (xlCellTypeBlanks)
Next lngCol
A. Where do I find the cell count for the rng.SpecialCells statement? If it is equal to the number of rows in the column - 1 then the users entered not data into that column and it should be deleted. I think I am on the right track but something is missing. Can someone help me on this?
B. What is the best way to delete a column if it is not necessary? Is there a Columns collection somewhere in the worksheet item I can reference?
C. Previous to the above, I want to copy Sheet1 to Sheet2 and then if changes are made, I will rename Sheet2 to Original Sheet. How is the best way to do this in VBA. If I don't make changes how do I delete Sheet2?
D. I am used to spinning collections in Forms, QueryDefs, TableDefs, etc in Access. What are the major collections when working with Excel?
E. Is there an Office equivalent of Access Developers Handbook?
I'm sorry if the answers to these are obvious, but I remember beating my head against the wall with the same types of things learning Access and I would like to spare myself some pain if I can.
Thanks in advance for any help and/or suggestions!
Have a great day!