LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 10,593
Default Trouble with VBA code for Excel.

A bit simpler

Public Sub ProcessData()
Dim i As Long
Dim iLastRow As Long

With ActiveSheet

iLastRow = .Cells(.Rows.Count, "A").End(xlUp).Row
For i = iLastRow To 2 Step -1
If .Cells(i, "C").Value = .Cells(i - 1, "C").Value Then
.Rows(i).Delete
End If
Next i

End With

End Sub

--
HTH

Bob

(there's no email, no snail mail, but somewhere should be gmail in my addy)

"JE" wrote in message
...
A colleague wrote vba code and has left town for 2 weeks before testing. I
believe I identified the correct section of code causing the problem
however,
I am only learning vba programming. This may be out of scope for this
forum
but is someone able to read the code and determine if it appears to be
correct. If yes, I will continue troubleshooting.

The file that is to be manipulated looks like:
A B C
D E
563 ACCOUNT: 4MV159560 SHORT NAME: SMITH
581 ACCOUNT: 4MV177935 SHORT NAME: WACKER
601 ACCOUNT: 4MV202709 SHORT NAME: LAITINEN
661 ACCOUNT: 4MV202709 SHORT NAME: LAITINEN
676 ACCOUNT: 4MV215032 SHORT NAME: HIEB

What the code should do is:
IF Col C for given line matches Col C for the row above, delete the line.
For instance, the row beginnign with 661 (in col A) would be deleted
because
Col C in the line above (601 in col A) matches.

The code written is:

Dim wks As Worksheet
Dim rngFound As Range
Dim RngToSearch As Range
Dim EndCell As Range

Set wks = Worksheets(4)
Set RngToSearch = wks.Columns("b")
Set rngFound = RngToSearch.Find(What:="ACCOUNT:", LOOKAT:=xlPart)

Range("a1", rngFound.Offset(-1, 0)).EntireRow.Delete


Cells(Worksheets(4).UsedRange.SpecialCells(xlCellT ypeLastCell).Row).Select

Set RngToSearch = wks.Columns("b")
Set rngFound = RngToSearch.Find(What:="ACCOUNT:", LOOKAT:=xlPart,
searchdirection:=xlPrevious)

a = Worksheets(4).UsedRange.SpecialCells(xlCellTypeLas tCell).Row

Set EndCell = Cells(a, 2)

Range(rngFound.Offset(1, 0), EndCell).EntireRow.Delete
Range("a1").Select

Range("c1").Select
Selection.CurrentRegion.Sort Key1:=Range("C1"), Order1:=xlAscending,
Order2:=xlAscending, Header:=xlGuess, OrderCustom:=1, _
MatchCase:=False, Orientation:=xlTopToBottom,
DataOption1:=xlSortNormal, _
DataOption2:=xlSortNormal

acctnum = Range("c1").Value

For b = 2 To
Worksheets(4).UsedRange.SpecialCells(xlCellTypeLas tCell).Row
If Cells(b, 3) = acctnum Then
Rows(b).Delete
b = b - 1
End If
acctnum = Cells(b, 3)
Next b

When the query was run, it looped and finally errored due to no records
retrieved.

Again, if this question is out of scope, please let me know. Thank you.



 
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
Trouble with code JOUIOUI Excel Programming 3 February 27th 07 05:01 PM
Trouble with Code, but only sometimes JOUIOUI Excel Programming 0 December 15th 06 01:18 PM
Trouble with this code JOUIOUI Excel Programming 3 November 7th 06 12:35 AM
Trouble with this code JOUIOUI Excel Programming 4 June 11th 06 04:49 PM
Trouble Adding VBA Code to Module; Bug in Excel/VBE? Mat P:son Excel Programming 4 April 20th 06 04:17 PM


All times are GMT +1. The time now is 02: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"