Tim Wardlaw
Limp Gawd
- Joined
- May 13, 2002
- Messages
- 360
Hey guys,
I have searched around on a bunch of sites and have not been able to find code that would suite my needs. What I am trying to do is the following. I have one script that goes out and scans all servers on our network and dumps all the results into separate tab delimited files. (Over 300 files). Now the script that I am working on now will append each file onto a master file with a little bit of other search ability options being added at the same time. My problem is writing code that will tell me what the last cell in a column is that contains data. I have found many examples but none really seem to work in my code.
For some reason the SpecialCell call does not work in my code. Gives Unable to get SpecialCells property of the Range class error.
Here is a snippet of my code:
Sorry if my notes are shitty, post if you need clarification with anything.
If anyone could help me out it would be much appreciated!
I have searched around on a bunch of sites and have not been able to find code that would suite my needs. What I am trying to do is the following. I have one script that goes out and scans all servers on our network and dumps all the results into separate tab delimited files. (Over 300 files). Now the script that I am working on now will append each file onto a master file with a little bit of other search ability options being added at the same time. My problem is writing code that will tell me what the last cell in a column is that contains data. I have found many examples but none really seem to work in my code.
For some reason the SpecialCell call does not work in my code. Gives Unable to get SpecialCells property of the Range class error.
Here is a snippet of my code:
Code:
Dim objexcel
Dim w_Name
Dim Filename
Dim FSO
Dim EOF
Dim Name
Dim ExcelLastCell
Dim LastColWithData
Dim Col
'On Error Resume Next
'This checks to see if excel is running, if not it opens it
'******SUB 1
Set objexcel = GetObject(, "Excel.Application")
If TypeName(objexcel) = "Empty" Then
Set objexcel = createobject("Excel.application") '<--Opens Excel
End If
objexcel.Visible = True '<-- Makes it visible
'******END SUB 1
'This opens a file with the names of all the files needed.
'******SUB 2
Filename = "D:\Data\Scripts\Permission_Compile\DIR.txt" '<--Location of list of file Names
Set FSO = CreateObject("Scripting.FileSystemObject") '<--This loop opens the file and reads each line.
Set EOF = FSO.OpenTextFile(Filename) '<--The names are used to open each file.
Do Until EOF.AtEndOfStream
Name = trim(EOF.ReadLine)
objexcel.Workbooks.open("D:\Data\Scripts\Permission_Compile\Files\" & Name) '<--Opens specific File.
objexcel.Selection.EntireColumn.Insert '<--Inserts a column
w_Name = objexcel.ActiveCell.Worksheet.Name '<--Grabs name of worksheet since it is based on server name.
ExcelLastCell = objexcel.Application.ActiveCell.SpecialCells(xlLastCell)
' Determine the last column with data in it (must also copy the top para for this to work)
LastColWithData = objexcel.ExcelLastCell.Column
Col = ExcelLastCell.Column
Do While objexcel.Application.CountA(objexcel.ActiveSheet.Columns(Col)) = 0 And Col <> 1
Col = Col - 1
Loop
LastColWithData = Col' Column number
MsgBox LastColWithData,"Col Status"
'If Not objexcel.ActiveSheet.AutoFilterMode Then
' objexcel.ActiveSheet.Range("C1:C65536").AutoFilter
' End If
Loop
EOF.Close
Sorry if my notes are shitty, post if you need clarification with anything.
If anyone could help me out it would be much appreciated!
