PDA

View Full Version : code to copy content to adjacent cells based on a cell value



anbarasi_r
05-27-2015, 01:40 PM
I'm looking for a code in certain columns which copies a text to adjacent cells based on a cell value. If a cell in column contains the desired text then 3 adjacent cells to the left of column should also contain the same text

Attaching my sheet here 13533

If you look at the sheet, Column I, M, Q, U needs to be checked for "Dismissed". If any cell contains dismissed the 4 adjacent cells to left also need to contain "dismissed"

eg: if M6 is found to contain "Dismissed" then the same needs to be copied to cells J6, K6 and L6

Any help is appreciated.
Thanks in advance

mperrah
05-28-2015, 08:46 AM
Sub vbax52717()
' 5/28/2015 mperrah

Dim r, c, lr As Long

lr = Cells(Rows.Count, 1).End(xlUp).Row

For r = 2 To lr
For c = 8 To 20 Step 4
If Cells(r, c) = "Dismissed" Then Cells(r, c).Copy Cells(r, c - 4).Resize(, 4)
Next c
Next r
End Sub