![]() |
![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
| Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks. |
| |||||||
![]() |
| |
| | #1 (permalink) |
| | Finding the last row of and excel worksheet. Hi all, I have a script that goes out and searches a spreadsheet for information. If it finds a null value, I need my script to open up another logging spreadsheet and look into Column B (Column A has preset Error ID numbers to help identify the problem) and find the next open row, then input a text description. I have everythign working great, except for I can't for the life of me figure out what code I'm supposed to put in to find the next available row in excel. '~~~~~~~~~~~Visual of what my Error Spreadsheet should read~~~~~~~~~~~~~~~ Col A Col B ID # Issue ID 2 Null Value ID 3 Null Value ID 4 ID 5 '~~~~~~~~~~~My script that needs help - Not all of script~~~~~~~~~~~~~~~~~~~~~~~~ Set objExcel = CreateObject("Excel.Application") objExcel.Workbooks.Open ("C:\Excelfilename.xls") Set objSheet = objExcel.ActiveWorkbook.WorkSheets(1) IntRow = 9 K = 11 R = 18 if objExcel.Cells(intRow, K).Value <> "" then objExcel.Cells(intRow, R).Interior.ColorIndex = 4 else objExcel.Visible = False objExcel.Workbooks.Open("C:\ErrorLog.xls") objExcel.Cells(NEXTOPENROW, R) = "Null Value" <==========THIS IS WHERE I NEED HELP======== End If I put NEXTOPENROW in the above script to let you know that's where i need help with, that's not part of my script, I have no idea how to find the next open row....any help is appriciated!!!!! |
My System Specs![]() |
| | #2 (permalink) |
| | Re: Finding the last row of and excel worksheet. GBPackerBacker schrieb: Quote: > Hi all, I have a script that goes out and searches a spreadsheet for > information. If it finds a null value, I need my script to open up > another logging spreadsheet and look into Column B (Column A has > preset Error ID numbers to help identify the problem) and find the > next open row, then input a text description. > > I have everythign working great, except for I can't for the life of me > figure out what code I'm supposed to put in to find the next available > row in excel. Try something like: Const xlLastCell = 11 ... = <WorkSheet>.UsedRange.SpecialCells( xlLastCell ) |
My System Specs![]() |
| | #3 (permalink) |
| | Re: Finding the last row of and excel worksheet. "GBPackerBacker" <gbpackerbacker@xxxxxx> wrote in message news:2699deec-49bc-44c3-a02b-c30f0a99029c@xxxxxx Quote: > Hi all, I have a script that goes out and searches a spreadsheet for > information. If it finds a null value, I need my script to open up > another logging spreadsheet and look into Column B (Column A has > preset Error ID numbers to help identify the problem) and find the > next open row, then input a text description. > > I have everythign working great, except for I can't for the life of me > figure out what code I'm supposed to put in to find the next available > row in excel. > > '~~~~~~~~~~~Visual of what my Error Spreadsheet should > read~~~~~~~~~~~~~~~ > Col A Col B > ID # Issue > ID 2 Null Value > ID 3 Null Value > ID 4 > ID 5 > > '~~~~~~~~~~~My script that needs help - Not all of > script~~~~~~~~~~~~~~~~~~~~~~~~ > Set objExcel = CreateObject("Excel.Application") > objExcel.Workbooks.Open ("C:\Excelfilename.xls") > Set objSheet = objExcel.ActiveWorkbook.WorkSheets(1) > > IntRow = 9 > K = 11 > R = 18 > > if objExcel.Cells(intRow, K).Value <> "" then > objExcel.Cells(intRow, R).Interior.ColorIndex = 4 > else > objExcel.Visible = False > objExcel.Workbooks.Open("C:\ErrorLog.xls") > objExcel.Cells(NEXTOPENROW, R) = "Null Value" <==========THIS IS > WHERE I NEED HELP======== > End If > > I put NEXTOPENROW in the above script to let you know that's where i > need help with, that's not part of my script, I have no idea how to > find the next open row....any help is appriciated!!!!! found this solution: Function LastRow Const xlCellTypeLastCell = 11 oSheet.UsedRange.SpecialCells(xlCellTypeLastCell).Activate LastRow = oExcel.ActiveCell.Row End LastRow |
My System Specs![]() |
| | #4 (permalink) |
| | Re: Finding the last row of and excel worksheet. On Mar 31, 1:56*pm, "ekkehard.horner" <ekkehard.hor...@xxxxxx> wrote: Quote: > GBPackerBacker schrieb:> Hi all, I have a script that goes out and searches a spreadsheet for Quote: > > information. If it finds a null value, I need my script to open up > > another logging spreadsheet and look into Column B (Column A has > > preset Error ID numbers to help identify the problem) and find the > > next open row, then input a text description. Quote: > > I have everythign working great, except for I can't for the life of me > > figure out what code I'm supposed to put in to find the next available > > row in excel. > [...] > Try something like: > > * *Const xlLastCell = 11 > * *... = <WorkSheet>.UsedRange.SpecialCells( xlLastCell ) Thanks for the info, I'll see if I can get it to work, in the meantime, can you explain a little more? What is the significance of xlLastCell = 11. What does 11 mean? Also, once I find the cell, how do I set that row number as a variable? For instance, once the cell is found, I want to input a number into the cell, but also use that same row to enter in information in a couple different columns.... Example below... else objExcel.Visible = False objExcel.Workbooks.Open("C:\ErrorLog.xls") varRow = <WorkSheet>.UsedRange.SpecialCells( xlLastCell ) objExcel.Cells(VarRow, R) = "Null Value" objExcel.Cells(VarRow, S) = "Today's Date" IdNum = (contentsofpreviouscell) +1 objExcel.Cells(VarRow, A) = IdNum End If |
My System Specs![]() |
| | #5 (permalink) |
| | Re: Finding the last row of and excel worksheet. Okay Pegasus, I can get your script to work great on a test excel spreadsheet, but when I plug it into my master script (snippet below) it errors out with the error: "Activate method of Range class failed" Code: 800A03EC. Any ideas? else objExcel.Visible = False objExcel.Workbooks.Open("C:\test.xls") Const xlCellTypeLastCell = 11 objSheet.UsedRange.SpecialCells(xlCellTypeLastCell).Activate LastRow = objExcel.ActiveCell.Row FirstOpenRow = LastRow + 1 objExcel.Cells(FirstOpenRow, B) = strComputer objExcel.Cells(FirstOpenRow, G) = "NULL VALUE for MAC Address, in row " & intRow & ", Column K" End If |
My System Specs![]() |
| | #6 (permalink) |
| | Re: Finding the last row of and excel worksheet. "GBPackerBacker" <gbpackerbacker@xxxxxx> wrote in message news:0509e9d6-b01a-4107-82a2-6b1943e7ede8@xxxxxx Quote: > Okay Pegasus, I can get your script to work great on a test excel > spreadsheet, but when I plug it into my master script (snippet below) > it errors out with the error: "Activate method of Range class failed" > Code: 800A03EC. Any ideas? > > else > objExcel.Visible = False > objExcel.Workbooks.Open("C:\test.xls") > Const xlCellTypeLastCell = 11 > objSheet.UsedRange.SpecialCells(xlCellTypeLastCell).Activate > LastRow = objExcel.ActiveCell.Row > FirstOpenRow = LastRow + 1 > objExcel.Cells(FirstOpenRow, B) = strComputer > objExcel.Cells(FirstOpenRow, G) = "NULL VALUE for MAC Address, in > row " & intRow & ", Column K" > End If something like Set objSheet = objWorkbook.ActiveSheet and objWorkbook could be something like Set objWorkbook = objExcel.Workbooks.Open("d:\temp.xls") Try experimenting a little - it's very productive! |
My System Specs![]() |
| | #7 (permalink) |
| | Re: Finding the last row of and excel worksheet. GBPackerBacker schrieb: Quote: > On Mar 31, 1:56 pm, "ekkehard.horner" <ekkehard.hor...@xxxxxx> > wrote: Quote: >> GBPackerBacker schrieb:> Hi all, I have a script that goes out and searches a spreadsheet for Quote: >>> information. If it finds a null value, I need my script to open up >>> another logging spreadsheet and look into Column B (Column A has >>> preset Error ID numbers to help identify the problem) and find the >>> next open row, then input a text description. >>> I have everythign working great, except for I can't for the life of me >>> figure out what code I'm supposed to put in to find the next available >>> row in excel. >> Try something like: >> >> Const xlLastCell = 11 >> ... = <WorkSheet>.UsedRange.SpecialCells( xlLastCell ) > > Thanks for the info, I'll see if I can get it to work, in the > meantime, can you explain a little more? What is the significance of > xlLastCell = 11. What does 11 mean? Also, once I find the cell, how > do I set that row number as a variable? For instance, once the cell > is found, I want to input a number into the cell, but also use that > same row to enter in information in a couple different columns.... > Example below... The Const xlLastCell must be defined, because VBScript doesn't know about this Excel secrets. This sample code: Const xlLastCell = 11 Dim oFS : Set oFS = CreateObject( "Scripting.FileSystemObject" ) Dim sFSpec : sFSpec = oFS.GetAbsolutePathName( <your.xls> ) Dim oExcel : Set oExcel = CreateObject( "Excel.Application" ) Dim oWBook : Set oWBook = oExcel.Workbooks.Open( sFSpec ) Dim oSheet : Set oSheet = oWBook.Sheets( <yoursheet> ) Dim oLCell : Set oLCell = oSheet.UsedRange.SpecialCells( xlLastCell ) WScript.Echo oSheet.Cells( oLCell.Row, oLCell.Column ) oSheet.Cells( oLCell.Row + 1, oLCell.Column ) = Now oWBook.Save oWBook.Close oExcel.Quit appends the current date/time to the sheet. |
My System Specs![]() |
| | #8 (permalink) |
| | Re: Finding the last row of and excel worksheet. Pegasus [MVP] schrieb: Quote: > "GBPackerBacker" <gbpackerbacker@xxxxxx> wrote in message > news:0509e9d6-b01a-4107-82a2-6b1943e7ede8@xxxxxx Quote: >> Okay Pegasus, I can get your script to work great on a test excel >> spreadsheet, but when I plug it into my master script (snippet below) >> it errors out with the error: "Activate method of Range class failed" >> Code: 800A03EC. Any ideas? >> >> else >> objExcel.Visible = False >> objExcel.Workbooks.Open("C:\test.xls") >> Const xlCellTypeLastCell = 11 >> objSheet.UsedRange.SpecialCells(xlCellTypeLastCell).Activate >> LastRow = objExcel.ActiveCell.Row >> FirstOpenRow = LastRow + 1 >> objExcel.Cells(FirstOpenRow, B) = strComputer >> objExcel.Cells(FirstOpenRow, G) = "NULL VALUE for MAC Address, in >> row " & intRow & ", Column K" >> End If > Can't tell - you're not showing us your definition of objSheet. It should be > something like > Set objSheet = objWorkbook.ActiveSheet > > and objWorkbook could be something like > > Set objWorkbook = objExcel.Workbooks.Open("d:\temp.xls") > > Try experimenting a little - it's very productive! > > VBScript, because it is tied to interactive use. |
My System Specs![]() |
![]() |
| Thread Tools | |
| |
Similar Threads | ||||
| Thread | Forum | |||
| Can not open an existing Excel worksheet | PowerShell | |||
| Error when updating Access table from Excel Worksheet | VB Script | |||
| Excel Worksheet Tabs Disappeared in vista 64 | Microsoft Office | |||
| How to determin a worksheet exist in Excel? | PowerShell | |||
| Excel Worksheet | PowerShell | |||