Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 16
Default Finding criteria and removing matching rows (Range issue?)

I hope I can explain this one correctly.

Every time they do a system change around here, the columns of our data
change places. Luckly the headers are named the same in every case.

Therefore, part of my existing macro finds those header names and defines
that particular cell as a name within the worksheet. For instance, the macro
will search for the column header, "Title Classification", and define an
actual name of "Title" so that it can be used in other parts of the macro.
The defined "Title" then refers to cell x1 (where x is the "Title
Classification" column.) "Title" does not, however, refer to the entire
column.

Here's the dilema:

I would like to search the "Title" column for information as such:

Application.ScreenUpdating = False
lastrow = ActiveSheet.Cells(Rows.Count, "E").End(xlUp).Row
For row_index = lastrow - 1 To 1 Step -1
If Left(Cells(row_index, "E").Value, 9) = "Super Man" Then
Cells(row_index, "E").EntireRow.Delete
End If
Next
Application.ScreenUpdating = True

In the case above, it is assumed that column "E" contains the data. Truly,
that's not the case. It could be column "B", or "C", or anything else. One
thing for sure - It's the same column as the defined "Title" header.

The question:

Can I change where it says "E" to reflect the same column as "Title"? This
way, no matter where the column is, it will already be found and defined from
previous code?

Thanks to all who can help!

Cheers,

Ronny
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Finding criteria and removing matching rows (Range issue?)

Dim TitleCol As long
Dim TitleCell as range

with activesheet
with .rows(1) 'is the title in row 1?
set titlecell = .cells.find(what:="Title Classification", _
After:=.Cells(.Cells.Count), _
LookIn:=xlValues, _
LookAt:=xlWhole, _
SearchOrder:=xlByColumns, _
SearchDirection:=xlNext, _
MatchCase:=False)

if titlecell is nothing then
msgbox "Not found!!!
exit sub
end if
end with

titlecol = titlecell.column

Application.ScreenUpdating = False
lastrow = .Cells(Rows.Count, titlecol).End(xlUp).Row
For row_index = lastrow - 1 To 1 Step -1
If Left(.Cells(row_index, titlecol).Value, 9) = "Super Man" Then
.rows(row_index).EntireRow.Delete
End If
Next row_index
Application.ScreenUpdating = True
end with

========

I think I'd use:

If lcase(Left(.Cells(row_index, titlecol).Value, 9)) = lcase("Super Man") Then

(Just in case)

Ronny Hamida wrote:

I hope I can explain this one correctly.

Every time they do a system change around here, the columns of our data
change places. Luckly the headers are named the same in every case.

Therefore, part of my existing macro finds those header names and defines
that particular cell as a name within the worksheet. For instance, the macro
will search for the column header, "Title Classification", and define an
actual name of "Title" so that it can be used in other parts of the macro.
The defined "Title" then refers to cell x1 (where x is the "Title
Classification" column.) "Title" does not, however, refer to the entire
column.

Here's the dilema:

I would like to search the "Title" column for information as such:

Application.ScreenUpdating = False
lastrow = ActiveSheet.Cells(Rows.Count, "E").End(xlUp).Row
For row_index = lastrow - 1 To 1 Step -1
If Left(Cells(row_index, "E").Value, 9) = "Super Man" Then
Cells(row_index, "E").EntireRow.Delete
End If
Next
Application.ScreenUpdating = True

In the case above, it is assumed that column "E" contains the data. Truly,
that's not the case. It could be column "B", or "C", or anything else. One
thing for sure - It's the same column as the defined "Title" header.

The question:

Can I change where it says "E" to reflect the same column as "Title"? This
way, no matter where the column is, it will already be found and defined from
previous code?

Thanks to all who can help!

Cheers,

Ronny


--

Dave Peterson
  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 16
Default Finding criteria and removing matching rows (Range issue?)

Thank you, Dave!

"Dave Peterson" wrote:

Dim TitleCol As long
Dim TitleCell as range

with activesheet
with .rows(1) 'is the title in row 1?
set titlecell = .cells.find(what:="Title Classification", _
After:=.Cells(.Cells.Count), _
LookIn:=xlValues, _
LookAt:=xlWhole, _
SearchOrder:=xlByColumns, _
SearchDirection:=xlNext, _
MatchCase:=False)

if titlecell is nothing then
msgbox "Not found!!!
exit sub
end if
end with

titlecol = titlecell.column

Application.ScreenUpdating = False
lastrow = .Cells(Rows.Count, titlecol).End(xlUp).Row
For row_index = lastrow - 1 To 1 Step -1
If Left(.Cells(row_index, titlecol).Value, 9) = "Super Man" Then
.rows(row_index).EntireRow.Delete
End If
Next row_index
Application.ScreenUpdating = True
end with

========

I think I'd use:

If lcase(Left(.Cells(row_index, titlecol).Value, 9)) = lcase("Super Man") Then

(Just in case)

Ronny Hamida wrote:

I hope I can explain this one correctly.

Every time they do a system change around here, the columns of our data
change places. Luckly the headers are named the same in every case.

Therefore, part of my existing macro finds those header names and defines
that particular cell as a name within the worksheet. For instance, the macro
will search for the column header, "Title Classification", and define an
actual name of "Title" so that it can be used in other parts of the macro.
The defined "Title" then refers to cell x1 (where x is the "Title
Classification" column.) "Title" does not, however, refer to the entire
column.

Here's the dilema:

I would like to search the "Title" column for information as such:

Application.ScreenUpdating = False
lastrow = ActiveSheet.Cells(Rows.Count, "E").End(xlUp).Row
For row_index = lastrow - 1 To 1 Step -1
If Left(Cells(row_index, "E").Value, 9) = "Super Man" Then
Cells(row_index, "E").EntireRow.Delete
End If
Next
Application.ScreenUpdating = True

In the case above, it is assumed that column "E" contains the data. Truly,
that's not the case. It could be column "B", or "C", or anything else. One
thing for sure - It's the same column as the defined "Title" header.

The question:

Can I change where it says "E" to reflect the same column as "Title"? This
way, no matter where the column is, it will already be found and defined from
previous code?

Thanks to all who can help!

Cheers,

Ronny


--

Dave Peterson

Reply
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
Finding a Name on a list and returning all matching rows Wh0o Excel Worksheet Functions 2 August 18th 09 05:52 PM
sum all rows with multiple matching criteria The Fru Fru Excel Worksheet Functions 5 February 9th 09 12:25 AM
Finding matching numbers in different rows. classic3283 Excel Worksheet Functions 1 October 7th 08 04:26 AM
Finding One Value, Matching Three Criteria cattle mgr Excel Discussion (Misc queries) 2 August 29th 05 08:32 PM
Vlookup - finding more than one matching criteria Les Stout Excel Programming 0 January 14th 04 08:34 AM


All times are GMT +1. The time now is 09:28 AM.

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"