VBA to copy and paste cell from row above

Kimpnc

New Member
Joined
Aug 17, 2015
Messages
13
I have a sheet of raw data and column J has departments and Column C has SKUs
due to a couple of the lines being split at the POS 50% in one dept and 50% in another I need to write VBA which when it comes across SKU 4321 in cell C6 will copy the contents of cell J5 into J6.

I can do this fine when there is only one Dept 'option' by using:-

Sub Testing()
For i = 1 To 50000
With Sheets("Sheet1")
If .Range("C" & i).Value = "1234" Or .Range("C" & i).Value = "1235" Then _
.Range("J" & i).Value = "NEWLINE"
End With
Next i
End Sub

But item 4321 could need correcting to one of 4 Departments but ALWAYS the same as row above.
:confused:
 

Excel Facts

Format cells as time
Select range and press Ctrl+Shift+2 to format cells as time. (Shift 2 is the @ sign).
I have a sheet of raw data and column J has departments and Column C has SKUs
due to a couple of the lines being split at the POS 50% in one dept and 50% in another I need to write VBA which when it comes across SKU 4321 in cell C6 will copy the contents of cell J5 into J6.

I can do this fine when there is only one Dept 'option' by using:-

Sub Testing()
For i = 1 To 50000
With Sheets("Sheet1")
If .Range("C" & i).Value = "1234" Or .Range("C" & i).Value = "1235" Then _
.Range("J" & i).Value = "NEWLINE"
End With
Next i
End Sub

But item 4321 could need correcting to one of 4 Departments but ALWAYS the same as row above.
:confused:


I've sorted it :-) AND WORKING So hope it helps others

Sub Testing()
For i = 1 To 15000
With Sheets("Sheet1")

If .Range("c" & i).Value = "4321" Then _
.Range("J" & i).Value = "=R[-1]C"

End With
Next i
End Sub
 
Upvote 0

Forum statistics

Threads
1,223,164
Messages
6,170,444
Members
452,326
Latest member
johnshaji

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