Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3
Default move cell values over 2 cells

I'm using the code below, which I found here) and this works fine to
delete the row I want, but I want another bit of code that will find a
different value and then move cell values over two cells.

Here's the Delete Row code (this one works very well)

Sub Deleterows()
Dim lastrow As Long, a As Long, b As Long
Application.ScreenUpdating = False
lastrow = Cells(Rows.Count, "a").End(xlUp).Row
For a = lastrow To 2 Step -1
If Cells(a, "b") = "Projected" Then
Rows(a).EntireRow.Delete
End If
Next a
End Sub

Now, I want to find the Word 'Subtotal' in column B, say one is in
cell B80. What I would like is to move what is in Cell C80, D80, E80,
F80, G80, H80, I80 over 2 cells. Then move (what would be the new
cell value from E80 and F80 back to the left one cell. When all is
done cell E80 would then be blank..make sense?

  #2   Report Post  
Posted to microsoft.public.excel.programming
Jay Jay is offline
external usenet poster
 
Posts: 671
Default move cell values over 2 cells

Hi Rock -

Please clarify. If you move C80-I80 to the right two cells, then move the
new E80 and F80 back to the left one cell, I don't think E80 will be blank
(will it?). I believe the maneuver you describe leaves F80 and C80 blank.

Jay

"Rock" wrote:

I'm using the code below, which I found here) and this works fine to
delete the row I want, but I want another bit of code that will find a
different value and then move cell values over two cells.

Here's the Delete Row code (this one works very well)

Sub Deleterows()
Dim lastrow As Long, a As Long, b As Long
Application.ScreenUpdating = False
lastrow = Cells(Rows.Count, "a").End(xlUp).Row
For a = lastrow To 2 Step -1
If Cells(a, "b") = "Projected" Then
Rows(a).EntireRow.Delete
End If
Next a
End Sub

Now, I want to find the Word 'Subtotal' in column B, say one is in
cell B80. What I would like is to move what is in Cell C80, D80, E80,
F80, G80, H80, I80 over 2 cells. Then move (what would be the new
cell value from E80 and F80 back to the left one cell. When all is
done cell E80 would then be blank..make sense?


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3
Default move cell values over 2 cells

On Aug 15, 2:48 pm, Jay wrote:
Hi Rock -

Please clarify. If you move C80-I80 to the right two cells, then move the
new E80 and F80 back to the left one cell, I don't think E80 will be blank
(will it?). I believe the maneuver you describe leaves F80 and C80 blank.

Jay



"Rock" wrote:
I'm using the code below, which I found here) and this works fine to
delete the row I want, but I want another bit of code that will find a
different value and then move cell values over two cells.


Here's the Delete Row code (this one works very well)


Sub Deleterows()
Dim lastrow As Long, a As Long, b As Long
Application.ScreenUpdating = False
lastrow = Cells(Rows.Count, "a").End(xlUp).Row
For a = lastrow To 2 Step -1
If Cells(a, "b") = "Projected" Then
Rows(a).EntireRow.Delete
End If
Next a
End Sub


Now, I want to find the Word 'Subtotal' in column B, say one is in
cell B80. What I would like is to move what is in Cell C80, D80, E80,
F80, G80, H80, I80 over 2 cells. Then move (what would be the new
cell value from E80 and F80 back to the left one cell. When all is
done cell E80 would then be blank..make sense?- Hide quoted text -


- Show quoted text -


right, it gets a bit confusing...I was thinking need to move c80:I80
over 3 cells, then E80 and F80 back to the left...leaving F80 blank
and C80 as well. I guess another why would move e80:I80 over 3, then
c80:d80 over 2...something like that. I recorded this step but I
don't know how to apply it or translate to code....

  #4   Report Post  
Posted to microsoft.public.excel.programming
Jay Jay is offline
external usenet poster
 
Posts: 671
Default move cell values over 2 cells

Rock -

Below is code that moves the 7 cells to the right 2 spaces, then moves two
cells back to the left 1 space. This maneuver leaves C80 and F80 blank as
you describe.

If you start by moving the 7 cells to the right 3 spaces, you will end up
with 3 blank cells in the row no matter what you do. So, the code below lets
you modify the offsets to get the result you desire by trial and error:

Sub ModifySubtotalRows_Ver3()
Dim lastrow As Long, a As Long, b As Long
lastrow = Cells(Rows.Count, "a").End(xlUp).Row

'-------------------------------------
'Rock - modify the offset values in these two statements as needed
offset1 = 2 'number of columns to move C-I to the right
offset2 = 1 'number of columns to move two cells back to the left
'---------------------------------------

For a = lastrow To 2 Step -1
If Cells(a, "b") = "SubTotal" Then
Set anchorCell = Cells(a, "c")
anchorCell.Resize(1, 7).Cut Destination:=anchorCell.Offset(0, offset1)
anchorCell.Resize(1, 2).Cut Destination:=anchorCell.Offset(0, -1 *
offset2)
End If
Next a
End Sub

---
Jay

"Rock" wrote:

right, it gets a bit confusing...I was thinking need to move c80:I80
over 3 cells, then E80 and F80 back to the left...leaving F80 blank
and C80 as well. I guess another why would move e80:I80 over 3, then
c80:d80 over 2...something like that. I recorded this step but I
don't know how to apply it or translate to code....


  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 87
Default move cell values over 2 cells

Please try:
Sub MoveSubTs()
Dim lastrow As Long, a As Long
Application.ScreenUpdating = False
lastrow = Cells(Rows.Count, "a").End(xlUp).Row
For a = lastrow To 1 Step -1
If Cells(a, "b") = "Subtotal" Then
Cells(a, "c").Resize(1, 6).Cut Destination:=Cells(a, "e")
Cells(a, "e").Resize(1, 2).Cut Destination:=Cells(a, "d")
End If
Next a
End Sub


"Rock" wrote:

I'm using the code below, which I found here) and this works fine to
delete the row I want, but I want another bit of code that will find a
different value and then move cell values over two cells.

Here's the Delete Row code (this one works very well)

Sub Deleterows()
Dim lastrow As Long, a As Long, b As Long
Application.ScreenUpdating = False
lastrow = Cells(Rows.Count, "a").End(xlUp).Row
For a = lastrow To 2 Step -1
If Cells(a, "b") = "Projected" Then
Rows(a).EntireRow.Delete
End If
Next a
End Sub

Now, I want to find the Word 'Subtotal' in column B, say one is in
cell B80. What I would like is to move what is in Cell C80, D80, E80,
F80, G80, H80, I80 over 2 cells. Then move (what would be the new
cell value from E80 and F80 back to the left one cell. When all is
done cell E80 would then be blank..make sense?




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
Compare two cells, if equal move a third cell to another cell Mike Excel Discussion (Misc queries) 3 December 30th 08 07:26 PM
Sorting cells: a list behind the cells do not move with the cell Ross M Excel Discussion (Misc queries) 2 September 21st 06 12:14 PM
doubleclick to make cells move to another cell rayjay Excel Programming 1 March 6th 06 12:47 AM
In Excel, how do you move the contents of 3 cells into 1 cell? Lillie Excel Discussion (Misc queries) 2 January 4th 06 03:40 AM
How do I reference the same cell as I move through range of cells. MikeShep Excel Worksheet Functions 1 February 7th 05 12:12 PM


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