LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,501
Default IF Statement based on first two characters of cell

Glad I could help and thanks for the feedback


"PVANS" wrote:

Hi Mike and Steffi

Thanks for the advice. Mike, your one worked like a charm, thanks so much.
Really appreciate the help.

Regards

"Mike H" wrote:

Hi,

Try this. I wasn't sure if you wanted to add the shhets with code. This
doesn't, I have assumed they already exist

Sub stance()
Dim MyRange
Dim CopyrangeRetail As Range
Dim CopyrangeOpen As Range
lastrow = Cells(Cells.Rows.Count, "D").End(xlUp).Row
Set MyRange = Range("D1:D" & lastrow)
For Each c In MyRange
If UCase(Left(c.Value, 2)) = "CO" Then
If CopyrangeRetail Is Nothing Then
Set CopyrangeRetail = c.EntireRow
Else
Set CopyrangeRetail = Union(CopyrangeRetail, c.EntireRow)
End If
End If
If UCase(Left(c.Value, 2)) < "CO" Then
If CopyrangeOpen Is Nothing Then
Set CopyrangeOpen = c.EntireRow
Else
Set CopyrangeOpen = Union(CopyrangeOpen, c.EntireRow)
End If
End If
Next
If Not CopyrangeRetail Is Nothing Then
CopyrangeRetail.Copy Destination:=Sheets("DT Retail").Range("A1")
End If
If Not CopyrangeOpen Is Nothing Then
CopyrangeOpen.Copy Destination:=Sheets("DT CFD Open
Positions").Range("A1")
End If
End Sub


Mike

"PVANS" wrote:

Good morning,

I am currently using the following basic code to copy the contents of a
worksheet to another worksheet:
Sheets("DT Master").Select
Cells.Select
Selection.Copy
Sheets("DT CFD Open Positions").Select
Range("A1").Select
ActiveSheet.Paste

However, I have now discovered, that there are several rows of data within
the worksheet that should not be moved to the other worksheet, but instead be
placed on their own worksheet in the workbook.

The Column that determines which worksheet they need to be copied to is
Column D. If the cell begins with "C0", then it needs to be copied to a new
worksheet named "DT Retail"; if it begins with any other two characters, it
needs to be copied to the "DT CFD Open Positions" worksheet.

I think the best way to achieve this would be to use an IF ELSE statement.
However, as a result of further code run modifications of the data in "DT CFD
Open Positions", I would like the IF statement to first deal with the "DT
Retail" data, and then the "DT CFD Open Positions" data, ie:
IF column D starts with C0,
Copy rows to "DT Retail"
ELSE column D does not start with C0,
Copy rows to "DT CFD Open Positions"

Can someone please help me with the correct syntax and code? I would really
appreciate the help

Regards

 
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
How to lookup based in the first 3 characters of a cell Mas[_4_] Excel Discussion (Misc queries) 2 August 14th 11 12:04 PM
Need to add figures based on alpha characters in the same cell Frustrated in Iowa Excel Worksheet Functions 10 November 13th 08 09:16 PM
move data based on number of characters in a cell aileen Excel Programming 10 October 16th 08 08:53 PM
Merge a cell based on count of characters Red2003XLT Excel Discussion (Misc queries) 4 May 2nd 08 06:04 AM
Change color of characters in a cell based of a cell reference kimbobo Excel Programming 2 March 22nd 08 01:05 AM


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