Examples of VBA code to scan all rows and perform a function condi
dim Rng as Range
dim oCell as Range
dim LastRow as Long
dim J as long
LastRow= Worksheets("Sheet1").Range("D65536").End(xlUp).row
Set Rng = Worksheets("Sheet1").Range("D2").Resize(1,LastRow-1)
For J = LastRow to 2 Step -1
If Rng(J-1).Value = "Some Text" Then
Rng(J-1).EntireRow.Delete
Elseif Rng(J-1).Value = "Other Text" Then
"pjfarley3" wrote:
Hi all,
I have a need to scan all or some rows of an excel sheet, stopping at
rows that satisfy some condition (e.g., cell in column D = "some
text"). At each such row, I need to perform a function that will
modify the row as needed. Sometimes cells in the selected rows will be
modified, sometimes the row will be deleted.
As a separate task (probably best as a simple keystroke macro, I would
guess) I also need to be able to import additional rows to the "end" of
the sheet from an external file each month, probably in csv format
generated from a non-excel application. Then I will need to run the
"scan" program on the new rows to integrate them into the sheet.
Is there any example code out there that has this general scheme? I
have been looking at various code example sites, but none that I have
found so far have code to scan across all rows.
TIA for any urls/info/RTFM's you can provide.
Peter Farley
|