Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5
Default New to macros - find/move question

Hello,

I have a spreadsheet with a bunch of data in column A. I would like to

have a macro that starts at row 1, searches for predetermined sets of
text in A, and if found, cuts/pastes that row of text one cell up and
to the right.


Example.


Column A


Title
name
data
name
data
Title
name
test
name
test
name
data
Title


Each 'data' row and each 'test' row correspond with the 'name' above
it. Cut each 'data' row found and paste it into the the corresponding
'name' row (one above, one column over (column B)). Cut each 'name'
row found and paste it into the corresponding 'name' row (one row up
but column B).


** 'data' and 'test' rows contain other text as well, but cell will
"start" with either 'data' or 'test'. **


Rows will vary - not necessarily 'every other' because there are some
'titles' mixed in intermittently.


Any help would be appreaciated.


Thank you!

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 695
Default New to macros - find/move question

try this,- remember to make backup first right :-)

Sub Move()
Range(("A1"), Range("A65500").End(xlUp)).Select
For Each x In Selection
If x.Value = "test" Or x.Value = "data" Then
x.Copy Destination:=x.Offset(-1, 1)
x.EntireRow.Delete
End If
Next
End Sub

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5
Default New to macros - find/move question

Thank you for the response.

I tried the code, and all it seems to do is select all the cells in
Column A that contain data. Nothing is getting cut/pasted.

Not sure if this has anything to do with it, but the cells that contain
"test" or "data" contain other text as well - but they do begin with
"test" or "data".


Thank you.


excelent wrote:
try this,- remember to make backup first right :-)

Sub Move()
Range(("A1"), Range("A65500").End(xlUp)).Select
For Each x In Selection
If x.Value = "test" Or x.Value = "data" Then
x.Copy Destination:=x.Offset(-1, 1)
x.EntireRow.Delete
End If
Next
End Sub


  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5
Default New to macros - find/move question

That is exactly what is happening.

If the cell contains only 'test' or 'data', the macro works perfectly.
However, the cells only begin with 'test' or 'data' and have other
words after them - ex. "Data no 1".

Any way to make this macro work with an IF/Then that if x.value
CONTAINS or BEGINS with 'test' or 'data' instead of equals?


Thanks again.


n412 wrote:
Thank you for the response.

I tried the code, and all it seems to do is select all the cells in
Column A that contain data. Nothing is getting cut/pasted.

Not sure if this has anything to do with it, but the cells that contain
"test" or "data" contain other text as well - but they do begin with
"test" or "data".


Thank you.


excelent wrote:
try this,- remember to make backup first right :-)

Sub Move()
Range(("A1"), Range("A65500").End(xlUp)).Select
For Each x In Selection
If x.Value = "test" Or x.Value = "data" Then
x.Copy Destination:=x.Offset(-1, 1)
x.EntireRow.Delete
End If
Next
End Sub


  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 695
Default New to macros - find/move question

ok try

Sub Move()
Range(("A1"), Range("A65500").End(xlUp)).Select
For Each x In Selection
If x.Value Like "test*" Or x.Value Like "data*" Then
x.Copy Destination:=x.Offset(-1, 1)
x.EntireRow.Delete
End If
Next
End Sub


"n412" skrev:

That is exactly what is happening.

If the cell contains only 'test' or 'data', the macro works perfectly.
However, the cells only begin with 'test' or 'data' and have other
words after them - ex. "Data no 1".

Any way to make this macro work with an IF/Then that if x.value
CONTAINS or BEGINS with 'test' or 'data' instead of equals?


Thanks again.


n412 wrote:
Thank you for the response.

I tried the code, and all it seems to do is select all the cells in
Column A that contain data. Nothing is getting cut/pasted.

Not sure if this has anything to do with it, but the cells that contain
"test" or "data" contain other text as well - but they do begin with
"test" or "data".


Thank you.


excelent wrote:
try this,- remember to make backup first right :-)

Sub Move()
Range(("A1"), Range("A65500").End(xlUp)).Select
For Each x In Selection
If x.Value = "test" Or x.Value = "data" Then
x.Copy Destination:=x.Offset(-1, 1)
x.EntireRow.Delete
End If
Next
End Sub





  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5
Default New to macros - find/move question

Thank you - that did the trick.

A couple more questions, I am searching for about 15 values through
10000 lines of code. It takes about 4 minutes or so for the macro to
run. Is that normal, or is there a different way I should be doing
this based on the number of values I'm searching for.

Also, is there a way to take a different action (delete the row) for
two particular values if found - like an "Else If" statement?




excelent wrote:
ok try

Sub Move()
Range(("A1"), Range("A65500").End(xlUp)).Select
For Each x In Selection
If x.Value Like "test*" Or x.Value Like "data*" Then
x.Copy Destination:=x.Offset(-1, 1)
x.EntireRow.Delete
End If
Next
End Sub


"n412" skrev:

That is exactly what is happening.

If the cell contains only 'test' or 'data', the macro works perfectly.
However, the cells only begin with 'test' or 'data' and have other
words after them - ex. "Data no 1".

Any way to make this macro work with an IF/Then that if x.value
CONTAINS or BEGINS with 'test' or 'data' instead of equals?


Thanks again.


n412 wrote:
Thank you for the response.

I tried the code, and all it seems to do is select all the cells in
Column A that contain data. Nothing is getting cut/pasted.

Not sure if this has anything to do with it, but the cells that contain
"test" or "data" contain other text as well - but they do begin with
"test" or "data".


Thank you.


excelent wrote:
try this,- remember to make backup first right :-)

Sub Move()
Range(("A1"), Range("A65500").End(xlUp)).Select
For Each x In Selection
If x.Value = "test" Or x.Value = "data" Then
x.Copy Destination:=x.Offset(-1, 1)
x.EntireRow.Delete
End If
Next
End Sub




  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 695
Default New to macros - find/move question

oh my that was alot of rows :-)
try this for speed up

Sub Move()
Application.ScreenUpdating = False
Range(("A1"), Range("A65500").End(xlUp)).Select
For Each x In Selection
If x.Value Like "test*" Or x.Value Like "data*" Then
x.Copy Destination:=x.Offset(-1, 1)
x.EntireRow.Delete
End If
Next
Application.ScreenUpdating = True
End Sub


"n412" skrev:

Thank you - that did the trick.

A couple more questions, I am searching for about 15 values through
10000 lines of code. It takes about 4 minutes or so for the macro to
run. Is that normal, or is there a different way I should be doing
this based on the number of values I'm searching for.

Also, is there a way to take a different action (delete the row) for
two particular values if found - like an "Else If" statement?




excelent wrote:
ok try

Sub Move()
Range(("A1"), Range("A65500").End(xlUp)).Select
For Each x In Selection
If x.Value Like "test*" Or x.Value Like "data*" Then
x.Copy Destination:=x.Offset(-1, 1)
x.EntireRow.Delete
End If
Next
End Sub


"n412" skrev:

That is exactly what is happening.

If the cell contains only 'test' or 'data', the macro works perfectly.
However, the cells only begin with 'test' or 'data' and have other
words after them - ex. "Data no 1".

Any way to make this macro work with an IF/Then that if x.value
CONTAINS or BEGINS with 'test' or 'data' instead of equals?


Thanks again.


n412 wrote:
Thank you for the response.

I tried the code, and all it seems to do is select all the cells in
Column A that contain data. Nothing is getting cut/pasted.

Not sure if this has anything to do with it, but the cells that contain
"test" or "data" contain other text as well - but they do begin with
"test" or "data".


Thank you.


excelent wrote:
try this,- remember to make backup first right :-)

Sub Move()
Range(("A1"), Range("A65500").End(xlUp)).Select
For Each x In Selection
If x.Value = "test" Or x.Value = "data" Then
x.Copy Destination:=x.Offset(-1, 1)
x.EntireRow.Delete
End If
Next
End Sub




  #8   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5
Default New to macros - find/move question

Thank you - that did the trick.

A couple more questions, I am searching for about 15 values through
10000 lines of code. It takes about 4 minutes or so for the macro to
run. Is that normal, or is there a different way I should be doing
this based on the number of values I'm searching for.

Also, I've got a bunch of blank rows in my spreadsheet I'd like to
delete. I tried adding as ElseIf x.Value = "" Then x.EntireRow.Delete,
but that did not get rid of the rows.





excelent wrote:
ok try

Sub Move()
Range(("A1"), Range("A65500").End(xlUp)).Select
For Each x In Selection
If x.Value Like "test*" Or x.Value Like "data*" Then
x.Copy Destination:=x.Offset(-1, 1)
x.EntireRow.Delete
End If
Next
End Sub


"n412" skrev:

That is exactly what is happening.

If the cell contains only 'test' or 'data', the macro works perfectly.
However, the cells only begin with 'test' or 'data' and have other
words after them - ex. "Data no 1".

Any way to make this macro work with an IF/Then that if x.value
CONTAINS or BEGINS with 'test' or 'data' instead of equals?


Thanks again.


n412 wrote:
Thank you for the response.

I tried the code, and all it seems to do is select all the cells in
Column A that contain data. Nothing is getting cut/pasted.

Not sure if this has anything to do with it, but the cells that contain
"test" or "data" contain other text as well - but they do begin with
"test" or "data".


Thank you.


excelent wrote:
try this,- remember to make backup first right :-)

Sub Move()
Range(("A1"), Range("A65500").End(xlUp)).Select
For Each x In Selection
If x.Value = "test" Or x.Value = "data" Then
x.Copy Destination:=x.Offset(-1, 1)
x.EntireRow.Delete
End If
Next
End Sub




  #9   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 695
Default New to macros - find/move question

delete emty rows:

select A1
press and hold CTRL+SHIFT
pull down-arrow until all rows with values is selected
if u reach A65536 then pull up-arrow onse

now press F5 and click on Special
check out Emty cells
click ok

right click and select Delete


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
move to the right after hitting enter using macros Santa Fe Al Excel Discussion (Misc queries) 2 November 18th 09 07:45 PM
Move/Copy Worksheet with Macros Hansplay Excel Discussion (Misc queries) 2 October 9th 09 05:51 PM
Macros Move when Printing liz217 Excel Discussion (Misc queries) 2 August 22nd 05 03:32 PM
How do I move a toolbar with custom macros over to another computer? Colin Higbie Excel Programming 1 January 8th 05 09:39 PM
Can't Move Menu with Macros to Another Folder Arnold Dubin Excel Programming 1 June 4th 04 04:20 PM


All times are GMT +1. The time now is 06:25 AM.

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"