Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 48
Default copy values from one column to another with criteria

Hello all,
I am trying to copy all of the information in column A that starts with
"TC*" to column B. I would like to make this part of a macro but im unsure
how to get excel to select the cells in column A based on this criteria.

What my intended goal is to actually delete all entries in column A that
dont start with "TC*" or "MV*" . The only way I could figure to do this was
to copy them to column B, delete column A and then copy them back.. but if
anyone has a better way to do this please lend me a hand. Thanks!
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,123
Default copy values from one column to another with criteria

Try this one for A1:A100 (A1 is the header cell)

Sub Delete_with_Autofilter_Two_Criteria()
Dim DeleteValue As String
Dim DeleteValue2 As String
Dim rng As Range

DeleteValue = "<TC*"
DeleteValue2 = "<MV*"
With ActiveSheet
.Range("A1:A100").AutoFilter Field:=1, Criteria1:=DeleteValue, _
Operator:=xlAnd, Criteria2:=DeleteValue2
With ActiveSheet.AutoFilter.Range
On Error Resume Next
Set rng = .Offset(1, 0).Resize(.Rows.Count - 1, 1) _
.SpecialCells(xlCellTypeVisible)
On Error GoTo 0
If Not rng Is Nothing Then rng.EntireRow.Delete
End With
.AutoFilterMode = False
End With
End Sub


--
Regards Ron de Bruin
http://www.rondebruin.nl


"Michael A" wrote in message ...
Hello all,
I am trying to copy all of the information in column A that starts with
"TC*" to column B. I would like to make this part of a macro but im unsure
how to get excel to select the cells in column A based on this criteria.

What my intended goal is to actually delete all entries in column A that
dont start with "TC*" or "MV*" . The only way I could figure to do this was
to copy them to column B, delete column A and then copy them back.. but if
anyone has a better way to do this please lend me a hand. Thanks!



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 48
Default copy values from one column to another with criteria

Ron, Thanks for your help! That works great!

Im messing with it a little a bit and i have a question. Im trying to add in
a 3rd criteria. "<GFT*" .. However I get an error that tells me wrong # of
agruments. Could you explain how I could do this?

Thanks!



"Ron de Bruin" wrote:

Try this one for A1:A100 (A1 is the header cell)

Sub Delete_with_Autofilter_Two_Criteria()
Dim DeleteValue As String
Dim DeleteValue2 As String
Dim rng As Range

DeleteValue = "<TC*"
DeleteValue2 = "<MV*"
With ActiveSheet
.Range("A1:A100").AutoFilter Field:=1, Criteria1:=DeleteValue, _
Operator:=xlAnd, Criteria2:=DeleteValue2
With ActiveSheet.AutoFilter.Range
On Error Resume Next
Set rng = .Offset(1, 0).Resize(.Rows.Count - 1, 1) _
.SpecialCells(xlCellTypeVisible)
On Error GoTo 0
If Not rng Is Nothing Then rng.EntireRow.Delete
End With
.AutoFilterMode = False
End With
End Sub


--
Regards Ron de Bruin
http://www.rondebruin.nl


"Michael A" wrote in message ...
Hello all,
I am trying to copy all of the information in column A that starts with
"TC*" to column B. I would like to make this part of a macro but im unsure
how to get excel to select the cells in column A based on this criteria.

What my intended goal is to actually delete all entries in column A that
dont start with "TC*" or "MV*" . The only way I could figure to do this was
to copy them to column B, delete column A and then copy them back.. but if
anyone has a better way to do this please lend me a hand. Thanks!




  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,123
Default copy values from one column to another with criteria

Hi Michael

Autofilter have a maximum of 2 criteria
You can use Advanced filter to do it but you must enter your criteria in a range.

Or use a loop

Sub Example2()
Dim Lrow As Long
Dim CalcMode As Long
Dim StartRow As Long
Dim EndRow As Long
With Application
CalcMode = .Calculation
.Calculation = xlCalculationManual
.ScreenUpdating = False
End With

With ActiveSheet
.DisplayPageBreaks = False
StartRow = 1
EndRow = 100
For Lrow = EndRow To StartRow Step -1
If IsError(.Cells(Lrow, "A").Value) Then
'Do nothing, This avoid a error if there is a error in the cell

ElseIf Not Left(.Cells(Lrow, "A").Value, 2) = "TC" And _
Not Left(.Cells(Lrow, "A").Value, 2) = "MV" And _
Not Left(.Cells(Lrow, "A").Value, 3) = "GFT" Then .Rows(Lrow).Delete
End If
Next
End With
With Application
.ScreenUpdating = True
.Calculation = CalcMode
End With
End Sub

--
Regards Ron de Bruin
http://www.rondebruin.nl


"Michael A" wrote in message ...
Ron, Thanks for your help! That works great!

Im messing with it a little a bit and i have a question. Im trying to add in
a 3rd criteria. "<GFT*" .. However I get an error that tells me wrong # of
agruments. Could you explain how I could do this?

Thanks!



"Ron de Bruin" wrote:

Try this one for A1:A100 (A1 is the header cell)

Sub Delete_with_Autofilter_Two_Criteria()
Dim DeleteValue As String
Dim DeleteValue2 As String
Dim rng As Range

DeleteValue = "<TC*"
DeleteValue2 = "<MV*"
With ActiveSheet
.Range("A1:A100").AutoFilter Field:=1, Criteria1:=DeleteValue, _
Operator:=xlAnd, Criteria2:=DeleteValue2
With ActiveSheet.AutoFilter.Range
On Error Resume Next
Set rng = .Offset(1, 0).Resize(.Rows.Count - 1, 1) _
.SpecialCells(xlCellTypeVisible)
On Error GoTo 0
If Not rng Is Nothing Then rng.EntireRow.Delete
End With
.AutoFilterMode = False
End With
End Sub


--
Regards Ron de Bruin
http://www.rondebruin.nl


"Michael A" wrote in message ...
Hello all,
I am trying to copy all of the information in column A that starts with
"TC*" to column B. I would like to make this part of a macro but im unsure
how to get excel to select the cells in column A based on this criteria.

What my intended goal is to actually delete all entries in column A that
dont start with "TC*" or "MV*" . The only way I could figure to do this was
to copy them to column B, delete column A and then copy them back.. but if
anyone has a better way to do this please lend me a hand. Thanks!






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
Averaging values in column A when certain criteria are met in colu VichyB Excel Worksheet Functions 3 August 13th 09 02:51 AM
How do I count values w/ criteria located in more than one column Brian Excel Worksheet Functions 3 January 8th 07 05:14 AM
To copy values in a column relevant to text in an adjacent column? Guy Keon Excel Worksheet Functions 2 November 15th 05 08:10 PM
Sum the values of one column, only if they meet certain criteria . Todd Pippin Excel Worksheet Functions 0 February 8th 05 04:37 PM
Can I count values in column 1 if criteria in column 2 are met confounded office user Excel Worksheet Functions 2 November 9th 04 12:02 PM


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