VBA to copy cell value only into a range

danbates

Active Member
Joined
Oct 8, 2017
Messages
377
Office Version
  1. 2016
Platform
  1. 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
 

Excel Facts

Excel motto
Not everything I do at work revolves around Excel. Only the fun parts.
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?
 
Upvote 0
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
 
Upvote 0
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
 
Upvote 0
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
 
Upvote 0
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
 
Upvote 0

Forum statistics

Threads
1,213,527
Messages
6,114,148
Members
448,552
Latest member
WORKINGWITHNOLEADER

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