VBA - How to add multiple ranges using intersect

lintcollector

New Member
Joined
Mar 31, 2016
Messages
2
I'm new to VBA, and any recommendations on where to learn more would be greatly appreciated.

I have a spreadsheet where various employee's will fill in the date the complete their assignment, then it flows to the next person. I am trying to use VBA to create a "username" stamp for multiple columns.

This is what I have so far:

Private Sub Worksheet_Change(ByVal Target As Range)

Dim I As Range
Set I = Intersect(Range("D7:D252"), Target)

If I Is Nothing Then Exit Sub
Application.EnableEvents = False
Dim c As Range
For Each c In I
c.Offset(0, 1).Value = Environ("Username")
Next c

Application.EnableEvents = True

End Sub

I need to repeat the above but with additional ranges of cells: G7:G252, I7:I252,L7:L252 plus about 10 more columns with the same rows.

I've tried: Set I = Intersect(Range("D7:D252"),Range("G7:G252"), Range("I7:I252"),target)
and a few other guesses, but to no avail.

Help, pretty please!
 

Excel Facts

Select a hidden cell
Somehide hide payroll data in column G? Press F5. Type G1. Enter. Look in formula bar while you arrow down through G.
Sorry, just read the FAQ....

I'm new to <acronym title="visual basic for applications">VBA</acronym>, and any recommendations on where to learn more would be greatly appreciated.

I have a spreadsheet where various employee's will fill in the date the complete their assignment, then it flows to the next person. I am trying to use <acronym title="visual basic for applications">VBA</acronym> to create a "username" stamp for multiple columns.

This is what I have so far:

Code:
[COLOR=#0000ff]Private Sub Worksheet_Change(ByVal Target As Range)

Dim I As Range
Set I = Intersect(Range("D7:D252"), Target)

If I Is Nothing Then Exit Sub
    Application.EnableEvents = False
       Dim c As Range
       For Each c In I
       c.Offset(0, 1).Value = Environ("Username")
Next c

Application.EnableEvents = True

End Sub
[/COLOR][\CODE]

I need to repeat the above but with additional ranges of cells:    G7:G252, I7:I252,L7:L252 plus about 10 more columns with the same rows.   

I've tried: [COLOR=#0000ff]Set I =  Intersect(Range("D7:D252"),Range("G7:G252"), Range("I7:I252"),target)[/COLOR]
and a few other guesses, but to no avail.  

Help, pretty please!
 
Upvote 0

Forum statistics

Threads
1,215,412
Messages
6,124,761
Members
449,187
Latest member
hermansoa

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