Auto Copy values from row above based on cell value

Drumin_Phreak

New Member
Joined
Oct 10, 2016
Messages
25
Hello,

I'm new to VBA. my issue is this: If c7=c6 then d7,e7,f7, as well as p7:u7 (notice they are not consecutive) should auto fill with the values in their respective columns from the row above (row 6).


I have a code, but if I include "If IsEmpty(ActiveCell.Offset(i, i).Value) = False Then"
I find that it stops when I get passed g7 (as the value above it is blank). However, if I don't use it, the macro runs until it errors out.
Also the missing rows (the ones not mentioned here) are locked.


So the goal here is to Auto copy the above values in their respective columns if a condition is met in the ("C") column of the active cell's row.
Also, the copy effect will run until the last column in the row is reached ("U") and will not be interrupted if it encounters a locked cell.

Here is the code below


Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Dim myRng As Range
Set myRng = Range("now")

i = -1
Z = 1
If Intersect(Target, Range("now")) Is Nothing Then
ElseIf ActiveCell.Offset(0, i).Value = ActiveCell.Offset(i, i).Value Then

For Each x In myRng
If IsEmpty(ActiveCell.Offset(i, i).Value) = False Then
ActiveCell.Value = ActiveCell.Offset(i, 0).Value
ActiveCell.Offset(0, Z).Select
Else
Exit Sub

End If

Next x



End If
End Sub

I thank you very much for taking the time to listen to my issues, and look forward to your responses, and learning all I can in the process.
 

Excel Facts

Highlight Duplicates
Home, Conditional Formatting, Highlight Cells, Duplicate records, OK to add pink formatting to any duplicates in selected range.

Forum statistics

Threads
1,223,239
Messages
6,170,947
Members
452,368
Latest member
jayp2104

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