Can I make this shorter?

rutger

Board Regular
Joined
Apr 5, 2005
Messages
74
Hey there,
I was wondering if there's a way to make this code shorter?

Code:
    Cells(Target.Row, Target.Column + 2).Value = Target.Value
    Cells(Target.Row, Target.Column + 4).Value = Target.Value
    Cells(Target.Row, Target.Column + 6).Value = Target.Value
    Cells(Target.Row, Target.Column + 8).Value = Target.Value
    Cells(Target.Row, Target.Column + 10).Value = Target.Value
    Cells(Target.Row, Target.Column + 12).Value = Target.Value
    Cells(Target.Row, Target.Column + 14).Value = Target.Value
    Cells(Target.Row, Target.Column + 16).Value = Target.Value
    Cells(Target.Row, Target.Column + 18).Value = Target.Value
    Cells(Target.Row, Target.Column + 20).Value = Target.Value
    Cells(Target.Row, Target.Column + 22).Value = Target.Value
    Cells(Target.Row, Target.Column + 24).Value = Target.Value
    Cells(Target.Row, Target.Column + 26).Value = Target.Value
    Cells(Target.Row, Target.Column + 28).Value = Target.Value
    Cells(Target.Row, Target.Column + 30).Value = Target.Value
    Cells(Target.Row, Target.Column + 32).Value = Target.Value
    Cells(Target.Row, Target.Column + 34).Value = Target.Value
    Cells(Target.Row, Target.Column + 36).Value = Target.Value
    Cells(Target.Row, Target.Column + 38).Value = Target.Value

something like:

Cells(Target.Row, Target.Column +2, +4, etc.).value = Target.Value

Thanks in advance,
Rutger
 

Excel Facts

How to fill five years of quarters?
Type 1Q-2023 in a cell. Grab the fill handle and drag down or right. After 4Q-2023, Excel will jump to 1Q-2024. Dash can be any character.
try this code:

Code:
Sub Loop_Step()

For n = 2 to 38 Step 2
  Cells(Target.Row, Target.Column + n).Value = Target.Value
Next n

End Sub

Hope this helps some,
Andy :eek:
 
Upvote 0
Hey there Andy,

Thanks for the quick reply.
This does exactly what i had in mind.
Thanks again

Greetz,
Rutger
 
Upvote 0

Forum statistics

Threads
1,215,576
Messages
6,125,633
Members
449,242
Latest member
Mari_mariou

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