VBA to copy cell value only into a range

danbates

Active Member
Joined
Oct 8, 2017
Messages
280
Office Version
2016
Platform
Windows
Hi,

I have this following code:

Code:
If Not Intersect(Target, Range("C8")) Is Nothing Then
If Target.Value = 66 Then
    Target.Offset(, 1) = 66
    Target.Offset(, 1).AutoFill Range(Target.Offset(, 1), "Z" & Target.Row)
I would like to alter it so it does the following:

1. Copies anything entered in cell C8 to Z8.
2. Only copies the value and not the formatting of the cell.
3. If I delete the value in C8 it also deletes the rest of the values in the range as well.

Any help would be appreciated.

Kind Regards

Dan
 

Some videos you may like

Excel Facts

Enter current date or time
Ctrl+: enters current time. Ctrl+; enters current date. Use Ctrl+: Ctrl+; Enter for current date & time.

MisterProzilla

Active Member
Joined
Nov 12, 2015
Messages
263
Hi,

I have this following code:

Code:
If Not Intersect(Target, Range("C8")) Is Nothing Then
If Target.Value = 66 Then
    Target.Offset(, 1) = 66
    Target.Offset(, 1).AutoFill Range(Target.Offset(, 1), "Z" & Target.Row)
I would like to alter it so it does the following:

1. Copies anything entered in cell C8 to Z8.
2. Only copies the value and not the formatting of the cell.
3. If I delete the value in C8 it also deletes the rest of the values in the range as well.

Any help would be appreciated.

Kind Regards

Dan

Something like this, maybe? When it's run, this will check to see if there's a value in C8 - if there is, it's copied to Z8, else Z8 is left blank.

Code:
If Range("C8").Value <> "" then
    Range("Z8").Value = Range("C8").value
Else
    Range("Z8").Value = ""
End If
Is that what you're after?
 

steve the fish

Well-known Member
Joined
Oct 20, 2009
Messages
8,055
Office Version
365
Platform
Windows
Im not sure exactly what point 3 means but maybe try:

Code:
Private Sub Worksheet_Change(ByVal Target As Range)

If Not Intersect(Target, Range("C8")) Is Nothing Then Range("Z8").Value = Target.Value

End Sub
 

My Aswer Is This

Well-known Member
Joined
Jul 5, 2014
Messages
16,743
Office Version
2013
Platform
Windows
Try this:
Code:
Private Sub Worksheet_Change(ByVal Target As Range)
'Modified 6/5/18 4:20 AM EDT
If Not Intersect(Target, Range("C8")) Is Nothing Then
If Target.Cells.CountLarge > 1 Or IsEmpty(Target) Then Exit Sub
Target.Offset(, 23).Value = Target.Value
End If
End Sub
 

danbates

Active Member
Joined
Oct 8, 2017
Messages
280
Office Version
2016
Platform
Windows
Hi,

It's very close. I've just read my post again and I didn't exactly put it how I wanted.

When I said "1. Copies anything entered in cell C8 to Z8." I meant as a range C8:Z8.

Sorry my mistake.

Thanks
Dan
 

My Aswer Is This

Well-known Member
Joined
Jul 5, 2014
Messages
16,743
Office Version
2013
Platform
Windows
Try this:
Code:
Private Sub Worksheet_Change(ByVal Target As Range)
'Modified 6/5/18 4:40 AM EDT
If Not Intersect(Target, Range("C8")) Is Nothing Then
If Target.Cells.CountLarge > 1 Or IsEmpty(Target) Then Exit Sub
Target.Resize(, 24).Value = Target.Value
End If
End Sub
 

Watch MrExcel Video

Forum statistics

Threads
1,096,283
Messages
5,449,447
Members
405,567
Latest member
JeIIyfish

This Week's Hot Topics

Top