Private Sub Worksheet_Change(ByVal Target As Range)
' Code goes in the Worksheet specific module
Dim Rng As Range
' Set Target Range, i.e. Range("A1, B2, C3"), or Range("A1:B3")
Set Rng = Target.Parent.Range("A:A")
' Only look at single cell changes
If Target.Count > 1 Then Exit Sub
' Only look at that range
If Intersect(Target, Rng) Is Nothing Then Exit Sub
' Action if Condition(s) are met (do your thing here...)
Target.Offset(0, 3).Value = Target.Value
End Sub
Private Sub Worksheet_Change(ByVal Target As Range)
' Code goes in the Worksheet specific module
Dim Rng As Range
Dim LC As Long
LC = Cells(1, Columns.Count).End(xlToLeft).Column
' Set Target Range, i.e. Range("A1, B2, C3"), or Range("A1:B3")
Set Rng = Target.Parent.Range("A1")
' Only look at single cell changes
If Target.Count > 1 Then Exit Sub
' Only look at that range
If Intersect(Target, Rng) Is Nothing Then Exit Sub
' Action if Condition(s) are met (do your thing here...)
If Range("D1").Value = "" Then
Target.Offset(0, 3).Value = Target.Value
Else
Target.Offset(0, LC).Value = Target.Value
End If
End Sub
Private Sub Worksheet_Change(ByVal Target As Range)
' Code goes in the Worksheet specific module
Dim Rng As Range
Dim LR As Long
LR = Cells(Rows.Count, 4).End(xlUp).Row
' Set Target Range, i.e. Range("A1, B2, C3"), or Range("A1:B3")
Set Rng = Target.Parent.Range("A1")
' Only look at single cell changes
If Target.Count > 1 Then Exit Sub
' Only look at that range
If Intersect(Target, Rng) Is Nothing Then Exit Sub
' Action if Condition(s) are met (do your thing here...)
If Range("D1").Value = "" Then
Target.Offset(0, 3).Value = Target.Value
Else
Target.Offset(LR, 3).Value = Target.Value
End If
End Sub
thank you so much. if ever i wanted to change Coloumn a1 to another coloumn let us say to C1 and coloumn D to another coloumn.
what would i change with this code.
Private Sub Worksheet_Change(ByVal Target As Range)
'Code goes in the Worksheet specific module
Dim Rng As Range
Dim LR As Long
'Here the variable LR is set to column D
'This is used latter in the If statement to capture the last used cell in column D
LR = Range([COLOR="Red"]"D"[/COLOR] & Rows.Count).End(xlUp).Row
'If you do not want to start with A1...set it here
'Set Target Range, i.e. Range("A1, B2, C3"), or Range("A1:B3")
Set Rng = Target.Parent.Range([COLOR="red"]"A1"[/COLOR])
If Target.Count > 1 Then Exit Sub 'Only look at single cell changes
If Intersect(Target, Rng) Is Nothing Then Exit Sub 'Only look at that range
'If you do not want the value from A1 stored in column D with D1 as the first cell...change it here
'Action if Condition(s) are met (do your thing here...)
If Range([COLOR="red"]"D1"[/COLOR]).Value = "" Then
'The first time this macro is run the If statement will execute here
'Here we offset from A1 by 3 columns which is D1
Target.Offset(0, [COLOR="red"]3[/COLOR]).Value = Target.Value
Else
'After the first run through the macro will execute here
'Here we offset from A1 which is D1 and the variable LR produces a 1
'in the end...offset 3 columns to the right from A1 (D1) and then 1 row down (D2)
'and so on
Target.Offset(LR, [COLOR="red"]3[/COLOR]).Value = Target.Value
End If
End Sub