#1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 20
Default VBA Code...

Hi all,

I want to write a VBA (Excel) code to do the following...
Recognise when "Yes" is typed into any cell in column "C" on "sheet1"
and then cut that row, and paste it into the first empty row on
"sheet2", and finally delete the row on "sheet1".
Can anybody offer any suggestions/code as to how I can achieve this?


Many thanks,
Mark

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4,624
Default VBA Code...

One answer in the m.p.excel newsgroup.

In article om,
"MarkHear1" wrote:

Hi all,

I want to write a VBA (Excel) code to do the following...
Recognise when "Yes" is typed into any cell in column "C" on "sheet1"
and then cut that row, and paste it into the first empty row on
"sheet2", and finally delete the row on "sheet1".
Can anybody offer any suggestions/code as to how I can achieve this?


Many thanks,
Mark

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 9,101
Default VBA Code...

Thie code below should be placed in the code for worksheet1. go to Worksheet
page and rigght click on Sheet1 Tab and select code. the code will only be
called when there arre changes on sheett 1.

"Joel" wrote:

try this code

Private Sub Worksheet_Change(ByVal Target As Range)


Charcount = 1
If Target.Column < Range("C1").Column Then Exit Sub

If StrComp(StrConv(Target, vbUpperCase), "YES") < 0 Then Exit Sub

Set FirstRange = Target.EntireRow


FirstRange.Select
FirstRange.Cut


Worksheets("Sheet2").Select
RowOffset = 0

Do While StrComp(Worksheets("Sheet2").Range("a1"). _
Offset(RowOffset:=RowOffset, columnoffset:=0), "") < 0

RowOffset = RowOffset + 1
Loop


Set SecondRange = Worksheets("Sheet2").Range("A1"). _
Offset(RowOffset:=RowOffset, columnoffset:=0).EntireRow

SecondRange.Select
SecondRange.Insert (xlShiftDown)

End Sub


"MarkHear1" wrote:

Hi all,

I want to write a VBA (Excel) code to do the following...
Recognise when "Yes" is typed into any cell in column "C" on "sheet1"
and then cut that row, and paste it into the first empty row on
"sheet2", and finally delete the row on "sheet1".
Can anybody offer any suggestions/code as to how I can achieve this?


Many thanks,
Mark


  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 9,101
Default VBA Code...

try this code

Private Sub Worksheet_Change(ByVal Target As Range)


Charcount = 1
If Target.Column < Range("C1").Column Then Exit Sub

If StrComp(StrConv(Target, vbUpperCase), "YES") < 0 Then Exit Sub

Set FirstRange = Target.EntireRow


FirstRange.Select
FirstRange.Cut


Worksheets("Sheet2").Select
RowOffset = 0

Do While StrComp(Worksheets("Sheet2").Range("a1"). _
Offset(RowOffset:=RowOffset, columnoffset:=0), "") < 0

RowOffset = RowOffset + 1
Loop


Set SecondRange = Worksheets("Sheet2").Range("A1"). _
Offset(RowOffset:=RowOffset, columnoffset:=0).EntireRow

SecondRange.Select
SecondRange.Insert (xlShiftDown)

End Sub


"MarkHear1" wrote:

Hi all,

I want to write a VBA (Excel) code to do the following...
Recognise when "Yes" is typed into any cell in column "C" on "sheet1"
and then cut that row, and paste it into the first empty row on
"sheet2", and finally delete the row on "sheet1".
Can anybody offer any suggestions/code as to how I can achieve this?


Many thanks,
Mark


  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6,953
Default VBA Code...

Right click on the sheet tab of Sheet1 and select view code. Put in code
like this in the resulting module (for sheet1).

Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Count 1 Then Exit Sub
If Target.Column < 3 Then Exit Sub
On Error GoTo ErrHandler
If UCase(Trim(Target.Value)) = "YES" Then
Application.EnableEvents = False
Target.EntireRow.Copy _
Worksheets("Sheet2") _
.Cells(Rows.Count, 3) _
.End(xlUp)(2).EntireRow
Target.EntireRow.Delete
End If

ErrHandler:
Application.EnableEvents = True
End Sub

This is code for the change event. If you are not familiar with events, see
Chip Pearson's page for an overview http://www.cpearson.com/excel/events.htm

Note this will start placing data in row 2 of sheet 2. If you want to start
in row1 it will require some additional code.

--
Regards,
Tom Ogilvy


"MarkHear1" wrote:

Hi all,

I want to write a VBA (Excel) code to do the following...
Recognise when "Yes" is typed into any cell in column "C" on "sheet1"
and then cut that row, and paste it into the first empty row on
"sheet2", and finally delete the row on "sheet1".
Can anybody offer any suggestions/code as to how I can achieve this?


Many thanks,
Mark


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
split post code (zip code) out of cell that includes full address Concord Excel Discussion (Misc queries) 4 October 15th 09 06:59 PM
Shorten code to apply to all sheets except a few, instead of individually naming them, and later adding to code. Corey Excel Programming 3 December 11th 06 05:14 AM
Protect Sheet with code, but then code will not Paste error. How do i get around this. Please read for explainations.... Corey Excel Programming 4 November 25th 06 04:57 AM
Modification in the CODE to HIDE rows and columns that start with ZERO (code given) Thulasiram[_2_] Excel Programming 4 September 26th 06 04:15 AM
Excel code convert to Access code - Concat & eliminate duplicates italia Excel Programming 1 September 12th 06 12:14 AM


All times are GMT +1. The time now is 06:18 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"