VBA Moving a cell one cell to the right

alexfooty

Board Regular
Joined
Dec 30, 2018
Messages
97
Office Version
  1. 2016
Platform
  1. Windows
Hi
I have 21 columns of data C99:W99
Excel Move.png

I need a macro to move the orange cell (C100) one cell to the right each time the macro is run. When it eventually reaches cell W100 I need it to return to C100
Many thanks
 
Hope this is clearer.
I think so. :)
This also now uses columns E:Y as you requested in post #6

VBA Code:
Sub Move_Cell_v2()
  Dim rFound As Range
  
  Application.FindFormat.Clear
  Application.FindFormat.Interior.Color = RGB(255, 192, 0)
  Set rFound = Rows(100).Find(What:="", LookIn:=xlFormulas, SearchFormat:=True)
  If Not rFound Is Nothing Then
    Cells(81, rFound.Column).Resize(17).Value = Range("AC81:AC97").Value
    rFound.Cut Destination:=Cells(100, IIf(rFound.Column = 25, 5, rFound.Column + 1))
  End If
  Application.FindFormat.Clear
End Sub
 
Upvote 0

Excel Facts

When did Power Query debut in Excel?
Although it was an add-in in Excel 2010 & Excel 2013, Power Query became a part of Excel in 2016, in Data, Get & Transform Data.
Peter
Thank you. I called your macro from within a much larger macro that I use daily, and it works absolutely perfectly. Exactly what I wanted.
Thank you so much for all your help and patience.
Alex
 
Upvote 0
Peter
Any chance you could resend your code with comments explaining what each bit does? I'm trying to understand it but having difficulties.
It would help me greatly in trying to learn more about VBA.
Many thanks
Alex
 
Upvote 0
Sure

VBA Code:
Sub Move_Cell_v2()
  Dim rFound As Range
  
  'Clear any existing formatting settings for the Find process
  Application.FindFormat.Clear
  
  'Set the formatting that we want to look for (the orange cell)
  Application.FindFormat.Interior.Color = RGB(255, 192, 0)
  
  'Look in row 100 for the orange cell and set rFound to be that cell
  Set rFound = Rows(100).Find(What:="", LookIn:=xlFormulas, SearchFormat:=True)
  
  'This is just to stop the code erroring if there happens to be no orange cell in row 100
  If Not rFound Is Nothing Then
  
    'Starting at row 81 in the orange cell (rFound) column and for 17 cells from that one, transfer the values from column AC
    Cells(81, rFound.Column).Resize(17).Value = Range("AC81:AC97").Value
    
    'Cut the Orange cell and paste it 1 cell to the right (or to column E if we are at the end)
    rFound.Cut Destination:=Cells(100, IIf(rFound.Column = 25, 5, rFound.Column + 1))
    
  End If
  
  'Clear the orange formatting seeting from Find so that it doesn't impede any other Find operations that you might do
  Application.FindFormat.Clear
End Sub
 
Upvote 0
Peter, thank you so much. This is so helpful for me in trying to come to terms with VBA.
You have been so helpful and it's greatly appreciated.
Alex
 
Upvote 0
Peter, this is the last time I promise!
I've been trying to adapt your code, using a colored cell again rgb(0, 176, 240), but this time copying & pasting values from two rows of data then moving the colored cell down two cells.
The change from rows to columns threw me I must admit and I got myself into a right mess. Have you got the patience to supply one last macro - Please?

Image 1.png

I need to copy AN25:BK26 then paste the values into cells AN40:BK41 then the blue cell to move down two cells to AL42.
The next time the macro is run the vales will be pasted into AN42:BK43 etc

Image 2.png


The last position for the blue cell will be AN66, after which it returns to cell AL40.

Thanks
Alex
 
Upvote 0
Upvote 0
Hope this is a bit clearer Peter

From rows 25:26 to column AN beside the blue cell?
From cells AN25:BK26 to cells AN40:BK41 beside the blue cell. Then move the blue cell down 2 cells to AL42 so that the next time the macro is run the vales will be pasted into AN42:BK43 etc


If the blue cell is just moving down, how does it get from ALxx to ANxx?
Sorry it's a typo. Should read - The last position for the blue cell will be AL66, after which it returns to cell AL40.

 
Upvote 0

Forum statistics

Threads
1,215,094
Messages
6,123,069
Members
449,092
Latest member
ipruravindra

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top