PC Review


Reply
Thread Tools Rate Thread

Code modification?

 
 
=?Utf-8?B?ZnBkODMz?=
Guest
Posts: n/a
 
      21st Sep 2007
I was graciously provided a macro that deletes all rows not having certain
values in col A. In the following line:

ArrNames = Array("Agt", "Agent")

Is it possible to add a wildcard to "Agt"? Those are just the first 3
letters of the lines I'm looking for and are followed by more text. None of
the rows are unique and are being deleted as a result of the routine.

I have pasted the provided code below, should the above make no sense.

Thank you for your help!!

Ken


Sub Loop_Example()

Dim Firstrow As Long
Dim Lastrow As Long
Dim Lrow As Long
Dim CalcMode As Long
Dim ViewMode As Long
Dim ArrNames As Variant

With Application
CalcMode = .Calculation
.Calculation = xlCalculationManual
.ScreenUpdating = False
End With

With ActiveSheet
.Select

ViewMode = ActiveWindow.View
ActiveWindow.View = xlNormalView

.DisplayPageBreaks = False

Firstrow = .UsedRange.Cells(7).Row
Lastrow = .UsedRange.Rows(.UsedRange.Rows.Count).Row

ArrNames = Array(" Agt ID", "Agent Summary")

For Lrow = Lastrow To Firstrow Step -1

With .Cells(Lrow, "A")

If Not IsError(.Value) Then

If IsError(Application.Match(.Value, ArrNames, 0)) Then
..EntireRow.Delete

End If

End With

Next Lrow

End With

ActiveWindow.View = ViewMode
With Application
.ScreenUpdating = True
.Calculation = CalcMode
End With

End Sub

 
Reply With Quote
 
 
 
 
=?Utf-8?B?QmFyYiBSZWluaGFyZHQ=?=
Guest
Posts: n/a
 
      21st Sep 2007
I believe you could use the LIKE operator to do this.

If YourString like "ABC*" 'Finds cells that start with ABC.

If YourString like "*ABC*" 'Finds cells with ABC anywhere in them
--
HTH,
Barb Reinhardt



"fpd833" wrote:

> I was graciously provided a macro that deletes all rows not having certain
> values in col A. In the following line:
>
> ArrNames = Array("Agt", "Agent")
>
> Is it possible to add a wildcard to "Agt"? Those are just the first 3
> letters of the lines I'm looking for and are followed by more text. None of
> the rows are unique and are being deleted as a result of the routine.
>
> I have pasted the provided code below, should the above make no sense.
>
> Thank you for your help!!
>
> Ken
>
>
> Sub Loop_Example()
>
> Dim Firstrow As Long
> Dim Lastrow As Long
> Dim Lrow As Long
> Dim CalcMode As Long
> Dim ViewMode As Long
> Dim ArrNames As Variant
>
> With Application
> CalcMode = .Calculation
> .Calculation = xlCalculationManual
> .ScreenUpdating = False
> End With
>
> With ActiveSheet
> .Select
>
> ViewMode = ActiveWindow.View
> ActiveWindow.View = xlNormalView
>
> .DisplayPageBreaks = False
>
> Firstrow = .UsedRange.Cells(7).Row
> Lastrow = .UsedRange.Rows(.UsedRange.Rows.Count).Row
>
> ArrNames = Array(" Agt ID", "Agent Summary")
>
> For Lrow = Lastrow To Firstrow Step -1
>
> With .Cells(Lrow, "A")
>
> If Not IsError(.Value) Then
>
> If IsError(Application.Match(.Value, ArrNames, 0)) Then
> .EntireRow.Delete
>
> End If
>
> End With
>
> Next Lrow
>
> End With
>
> ActiveWindow.View = ViewMode
> With Application
> .ScreenUpdating = True
> .Calculation = CalcMode
> End With
>
> End Sub
>

 
Reply With Quote
 
=?Utf-8?B?ZnBkODMz?=
Guest
Posts: n/a
 
      21st Sep 2007
Thanks Barb! How/where would I work that into the code?

"Barb Reinhardt" wrote:

> I believe you could use the LIKE operator to do this.
>
> If YourString like "ABC*" 'Finds cells that start with ABC.
>
> If YourString like "*ABC*" 'Finds cells with ABC anywhere in them
> --
> HTH,
> Barb Reinhardt
>
>
>
> "fpd833" wrote:
>
> > I was graciously provided a macro that deletes all rows not having certain
> > values in col A. In the following line:
> >
> > ArrNames = Array("Agt", "Agent")
> >
> > Is it possible to add a wildcard to "Agt"? Those are just the first 3
> > letters of the lines I'm looking for and are followed by more text. None of
> > the rows are unique and are being deleted as a result of the routine.
> >
> > I have pasted the provided code below, should the above make no sense.
> >
> > Thank you for your help!!
> >
> > Ken
> >
> >
> > Sub Loop_Example()
> >
> > Dim Firstrow As Long
> > Dim Lastrow As Long
> > Dim Lrow As Long
> > Dim CalcMode As Long
> > Dim ViewMode As Long
> > Dim ArrNames As Variant
> >
> > With Application
> > CalcMode = .Calculation
> > .Calculation = xlCalculationManual
> > .ScreenUpdating = False
> > End With
> >
> > With ActiveSheet
> > .Select
> >
> > ViewMode = ActiveWindow.View
> > ActiveWindow.View = xlNormalView
> >
> > .DisplayPageBreaks = False
> >
> > Firstrow = .UsedRange.Cells(7).Row
> > Lastrow = .UsedRange.Rows(.UsedRange.Rows.Count).Row
> >
> > ArrNames = Array(" Agt ID", "Agent Summary")
> >
> > For Lrow = Lastrow To Firstrow Step -1
> >
> > With .Cells(Lrow, "A")
> >
> > If Not IsError(.Value) Then
> >
> > If IsError(Application.Match(.Value, ArrNames, 0)) Then
> > .EntireRow.Delete
> >
> > End If
> >
> > End With
> >
> > Next Lrow
> >
> > End With
> >
> > ActiveWindow.View = ViewMode
> > With Application
> > .ScreenUpdating = True
> > .Calculation = CalcMode
> > End With
> >
> > End Sub
> >

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
modification to this code James Microsoft Excel Misc 0 23rd Mar 2009 09:20 PM
Code modification please =?Utf-8?B?VG9t?= Microsoft Excel Programming 3 27th Apr 2007 02:22 PM
Modification in the CODE to HIDE rows and columns that start with ZERO (code given) Thulasiram Microsoft Excel Programming 4 26th Sep 2006 04:15 AM
Code Modification =?Utf-8?B?U2t5IFdhcnJlbg==?= Microsoft Access Form Coding 1 17th Mar 2005 07:48 PM
Code modification Mas Microsoft Excel Programming 3 29th Mar 2004 09:54 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 01:14 AM.