Is this VBA "Target,Offset" code proper or is there a better way?

EssKayKay

Board Regular
Joined
Jan 5, 2003
Messages
233
Office Version
  1. 2007
Platform
  1. Windows
I have some coding I use to "copy/paste special" after entering data into specific cells. It's doing what I want so maybe this is a silly question BUT, just wondering if there is some other more efficient or acceptable way to code this?

VBA Code:
    If IsDate(Target) Then Target.Offset(, -2).Value = Target.Offset(, -2).Value
    If IsDate(Target) Then Target.Offset(, -3).Value = Target.Offset(, -3).Value
    If IsDate(Target) Then Target.Offset(, -4).Value = Target.Offset(, -4).Value
    If IsDate(Target) Then Target.Offset(, -5).Value = Target.Offset(, -5).Value
    If IsDate(Target) Then Target.Offset(, -6).Value = Target.Offset(, -6).Value
    If IsDate(Target) Then Target.Offset(, -7).Value = Target.Offset(, -7).Value
    If IsDate(Target) Then Target.Offset(, -8).Value = Target.Offset(, -8).Value
    If IsDate(Target) Then Target.Offset(, -9).Value = Target.Offset(, -9).Value
    If IsDate(Target) Then Target.Offset(, -10).Value = Target.Offset(, -10).Value
    If IsDate(Target) Then Target.Offset(, -11).Value = Target.Offset(, -11).Value

Thanks,
Steve
 

Excel Facts

Format cells as currency
Select range and press Ctrl+Shift+4 to format cells as currency. (Shift 4 is the $ sign).
You can do it much more economically like this

VBA Code:
If IsDate(Target.Value) Then
  With Target.Offset(, -11).Resize(, 10)
    .Value = .Value
  End With
End If
 
Upvote 0
Solution
You can do it much more economically like this

VBA Code:
If IsDate(Target.Value) Then
  With Target.Offset(, -11).Resize(, 10)
    .Value = .Value
  End With
End If
That worked great. Thank you Peter - much appreciated.
 
Upvote 0
You're welcome. Thanks for the follow-up. :)
 
Upvote 0

Forum statistics

Threads
1,215,090
Messages
6,123,061
Members
449,091
Latest member
ikke

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