LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 18
Default Need help with odd behavior of worksheet rows

Hello,

I am working on a VB6 application that manipulates Excel Worksheets.

Right now I am working on code to delete rows identified with character 'r'
in column 1, and som of the wrong rows are deleted.
It looks as if Excel does nor recognize that rows have been deleted.

The code shown below is intended to delete the rows marked with 'r' and
leave the unmarked rows.
The sample I am using right now has column headers in row 1, as hown in the
small sample below, only the first 4 columns are shown:
The sheets contains only text, no formulas

Processed UserID
PolicyNumber Defendant
r FD3F55F4-D17D-4467-B45E-4008D295FE00 1212221 Dr.
Jones
r FD3F55F4-D17D-4467-B45E-4008D295FE00 1121222 Dr.
Hayes
r FD3F55F4-D17D-4467-B45E-4008D295FE00
r FD3F55F4-D17D-4467-B45E-4008D295FE00
r FD3F55F4-D17D-4467-B45E-4008D295FE00
FD3F55F4-D17D-4467-B45E-4008D295FE00
FD3F55F4-D17D-4467-B45E-4008D295FE00
FD3F55F4-D17D-4467-B45E-4008D295FE00

The code in question is:

Dim oCommonExcelWorkbook As Excel.WorkBook
Dim oCurrentSheet As Excel.WorkSheet

All variable starting with ln are declared as Long

For lnRowIndex = lnLastSourceRow To 1 Step -1
If (oCurrentSheet.Cells(lnRowIndex, 1) = "Processed") Then
Else
If (oCurrentSheet.Cells(lnRowIndex, 1) = "r") Then
oCurrentSheet.Activate
Range(Cells(lnSourceRow, 1), Cells(lnSourceRow,
lnColumnCount)).Select
Selection.Delete
oCommonExcelWorkbook.Save
End If
End If
Next lnRowIndex

The lnLastSourceRow holds the number of the last row with data in it, in
this case 9.
the lnColumnCount holds the number of columns with data in them, in this
case 15.
I chose to run the loop index backwards to avoid tripping up Excel with
respect to the row numbers, but it appears to get tripped up anyway.

The result of running the code, verified by stepping through, is that rows
9, 8, and 7 are skipped, as should happen, then row number 6 is deleted.
As the index passes theough 5, 4, 3, and 2, the 'r' is detected and the row
is deleted, everything looks fine.
However, at the end of the loop, the sheet, when viewed in Excel, shows that
the original rows 6 through 9 have been deleted, the original rows 1 through
5 are still there.
Am I missing something here?

Any help would be appreciated, this is driving me to distraction.

Ragnar




 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
arrow key behavior in protected worksheet Sarah B Excel Discussion (Misc queries) 0 February 2nd 07 04:44 PM
Weird worksheet saving behavior siouxland Excel Discussion (Misc queries) 0 October 12th 06 02:22 PM
Why does rngDataSource.Rows.Count = 65536 when worksheet Rows=95? [email protected] Excel Discussion (Misc queries) 12 July 22nd 05 12:50 PM
Problem with macro to copy worksheet--odd behavior DavidH[_2_] Excel Programming 0 November 1st 04 06:37 PM


All times are GMT +1. The time now is 05:33 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"