Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Help with find then copy macro

I am trying to get the code below to check through column Q of a
worksheet, when it finds a value that is in the case statement I want
to copy the entire row over to another worksheet.

So I'm trying to do this

Code:
--------------------
in worksheet "manning" check each cell in column Q
if cell = "actual"
then copy row to worksheet "actual"
if cell = "substantive"
then copy row to worksheet "substantive"
--------------------


At the moment it is not copying any data across.




Code:
--------------------
Dim Ws1 As Worksheet
Dim Ws2 As Worksheet
Dim Ws3 As Worksheet

Dim Ws1Q As Range

Dim ActualVacRow As Long
Dim SubstantiveVacRow As Long

Dim Cell1 As Range

Set Ws1 = Workbooks("manning.xls").Sheets("manning")
Set Ws2 = Workbooks("manning.xls").Sheets("Actual")
Set Ws3 = Workbooks("manning.xls").Sheets("Substantive")

Set Ws1Q = Ws1.Columns("Q")

For Each Cell1 In Ws1.Range("Q1:q" & Range("q65536").End(xlUp).Row)
Select Case UCase(C)
Case "ACTUAL": ActualVacRow = Ws2.Range("a65536").End(xlUp).Row + 1
Ws1.Rows(Cell1.Row).Copy Destination:=Ws2.Rows(ActualVacRow)
Case "SUBSTANTIVE": SubstantiveVacRow = Ws3.Range("a65536").End(xlUp).Row + 1
Ws1.Rows(Cell1.Row).Copy Destination:=Ws3.Rows(SubstantiveVacRow)
End Select
Next Cell1
--------------------



---
Message posted from http://www.ExcelForum.com/

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Help with find then copy macro

try ,

Dim Ws1 As Worksheet
Dim Ws2 As Worksheet
Dim Ws3 As Worksheet

Dim Ws1Q As Range

Dim ActualVacRow As Long
Dim SubstantiveVacRow As Long

Dim Cell1 As Range

Set Ws1 = Workbooks("manning.xls").Sheets("manning")
Set Ws2 = Workbooks("manning.xls").Sheets("Actual")
Set Ws3 = Workbooks("manning.xls").Sheets("Substantive")

Set Ws1Q = Ws1.Columns("Q")

For Each Cell1 In Ws1.Range("Q1:q"
Range("q65536").End(xlUp).Row)
Select Case UCase(Cell1.Value)
Case "ACTUAL"
ActualVacRow = Ws2.Range("a65536").End(xlUp).Row + 1
Ws1.Rows(Cell1.Row).Cop
Destination:=Ws2.Rows(ActualVacRow)
Case "SUBSTANTIVE"
SubstantiveVacRow = Ws3.Range("a65536").End(xlUp).Row
1
Ws1.Rows(Cell1.Row).Cop
Destination:=Ws3.Rows(SubstantiveVacRow)
Case Else
MsgBox Cell1.Value & " is unexpected"
End Select
Next Cell

--
Message posted from http://www.ExcelForum.com

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Help with find then copy macro

I gave it a go and I got the case else msg box straight up. I am
thinking it might have borked at the heading in column Q.

So I took out the case else and still nothing is copied across. :(


---
Message posted from http://www.ExcelForum.com/

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Help with find then copy macro

john_t_h,

After the heading was shown in the message box, did you get any further
messages displayed?
I am thinking that there may be trailing spaces etc in the text Actual,
substantive so try the following.
I ahve amended the range to exclude Q1 so the heading messge should not
appear.


Sub test()


Dim Ws1 As Worksheet
Dim Ws2 As Worksheet
Dim Ws3 As Worksheet

Dim Ws1Q As Range

Dim ActualVacRow As Long
Dim SubstantiveVacRow As Long

Dim Cell1 As Range

Set Ws1 = Workbooks("manning.xls").Sheets("manning")
Set Ws2 = Workbooks("manning.xls").Sheets("Actual")
Set Ws3 = Workbooks("manning.xls").Sheets("Substantive")

Set Ws1Q = Ws1.Columns("Q")

For Each Cell1 In Ws1.Range("Q2:q" &
Range("q65536").End(xlUp).Row)
Select Case Trim(UCase(Cell1.Value))
Case "ACTUAL"
ActualVacRow = Ws2.Range("a65536").End(xlUp).Row + 1
Cell1.EntireRow.Copy
Destination:=Ws2.Rows(ActualVacRow)
Case "SUBSTANTIVE"
SubstantiveVacRow = Ws3.Range("a65536").End(xlUp).Row +
1
Cell1.EntireRow.Copy
Destination:=Ws3.Rows(SubstantiveVacRow)
Case Else
MsgBox Cell1.Value & " is unexpected"
End Select
Next Cell1
End Sub


---
Message posted from http://www.ExcelForum.com/

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Help with find then copy macro

That did the trick thanks

:-)


---
Message posted from http://www.ExcelForum.com/



  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 100
Default Help with find then copy macro

try replacing the line
Select Case UCase(C)

to

Select Case UCase(Cell1)

Tony
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
Macro to find value and then copy associated range hnyb1 Excel Discussion (Misc queries) 1 December 31st 09 04:09 PM
Please help - Find & copy Macro Damil4real Excel Worksheet Functions 1 May 7th 09 02:30 PM
Find and Copy down macro Barry McConnell Excel Discussion (Misc queries) 4 July 1st 08 08:00 AM
FIND-COPY DIFFERENT WORDS WITH MACRO Spiros Excel Discussion (Misc queries) 3 September 27th 07 01:20 PM
FIND-COPY DIFFERENT WORDS WITH MACRO Spiros Excel Discussion (Misc queries) 1 September 27th 07 11:43 AM


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