|
|
|||||||
I am looking for the syntax for deleting rows in excel. I have looked all over but to no avail. I tried the xlRangeDelete() UDF but it doesn't do what I need as the sheets are protected but users have the right to delete entire rows. Thanks |
||||||||
|
|
|||||||
Maybe first Select the row: Rows("xx:yy").Select than do a Selection.Clear |
||||||||
|
|
|||||||
I'll give that a try but won't that just clear the contents of the cells? I need to delete the row completely. I am populating a template that is designed to accommodate a large subset of data but for the records that just populate a few line items, I want to delete the excess rows. Maybe I could hide them. As long as they don't print, that would work too. |
||||||||
|
|
|||||||
This shouldn't be to difficult to convert to Kix... How Can I Delete Specified Rows in an Excel Spreadsheet? http://www.microsoft.com/technet/scriptcenter/resources/qanda/jun07/hey0622.mspx |
||||||||
|
|
|||||||
Something like this. I tried to convert the VBScript in the article above to Kix but I can’t get it to enter the loop. My guess is that is has something to do with this line $objExcel.Cells($i, 1).Value = "". I'm not sure if this is proper kix syntax. The script below hangs on it. All lines above it execute properly but it stops when it should enter the loop. Code: Break on $objExcel = CreateObject("Excel.Application") $objExcel.Visible = True $objWorkbook = $objExcel.Workbooks.Open("D:\Test.xlsx") $i = 1 Do Until $objExcel.Cells($i, 1).Value = "" If $objExcel.Cells($i, 1).Value = "delete" $objRange = $objExcel.Cells($i, 1).EntireRow $objRange.Delete $i = $i - 1 EndIf $i = $i + 1 Loop [edit] Before someone starts shouting, the d:\text.xlsx (note the extra X) is not the issue. I have Office 2007 [/edit] |
||||||||
|
|
|||||||
well maybe this has something to do with it... Code: Do Until .... Loop Would "While" work better? |
||||||||
|
|
|||||||
@#$!%#$^@#$ Feeling kinda stupid Thanks Allen. Kix also has a Do Until but that would be Do ;stuff until $a = $b. Sure this can also be done with a Do until loop just not as I had it first. The script below works. Code: Break on $objExcel = CreateObject("Excel.Application") $objExcel.Visible = True $objWorkbook = $objExcel.Workbooks.Open("D:\Test.xlsx") $i = 1 While $objExcel.Cells($i, 1).Value <> "" If $objExcel.Cells($i, 1).Value = "delete" $objRange = $objExcel.Cells($i, 1).EntireRow $objRange.Delete $i = $i - 1 EndIf $i = $i + 1 Loop |
||||||||
|
|
|||||||
Quote: @#$!%#$^@#$ Feeling kinda stupid LOL... been there, done that many times |
||||||||
|
|
|||||||
Yeah it's a easy mistake to make. To quote Captain Alberto Bertorelli from the tv serie Allo, Allo. Whata mistaka ta maka!! |
||||||||
|
|
|||||||
What a great show. I just watched the first 6 seasons...Funny as hell! I'll try the script above tomorrow and let you know how it works for me! Thanks |
||||||||
|
|
|||||||
Originally Posted By: Herr Flick How many germans does it take to screw in a light bulb? Originally Posted By: Von Smallhousen 1? Originally Posted By: Herr Flick VE ASK ZE QUESTIONS!! |