Macro Help - Fairly Advanced.

N

NPell

Hello,

This is a bit of a re-post, but it seems to have fallen off the radar
a bit.

I have a macro that populates the username in a cell, that works fine.
But I dont want to have to Run the macro (or use Ctrl+Shift+U, as i
have assigned) for this to populate.

The username is needed to populate in M, based on the value of column
K being V

For example:
K M
-----------
v username

v username
v username

v username


K can only be "v" due to Data Validation. But it can be on any row.

Basically to put it in formula terms.
=IF($K1="v", Run Macro in M1)

Is this do-able? Ive seen suggestions with absolute cell references,
but this isnt absolute.

If anybody can help, or tell me if its even possible, it would be much
appreciated.
 
B

Bob Phillips

Private Sub Worksheet_Change(ByVal Target As Range)
Const WS_RANGE As String = "K:K" '<== change to suit

On Error GoTo ws_exit
Application.EnableEvents = False

If Not Intersect(Target, Me.Range(WS_RANGE)) Is Nothing Then
With Target
If .Value = "v" Then

.Offset(0, 2).Value = Environ("Username")
End If
End With
End If

ws_exit:
Application.EnableEvents = True
End Sub

'This is worksheet event code, which means that it needs to be
'placed in the appropriate worksheet code module, not a standard
'code module. To do this, right-click on the sheet tab, select
'the View Code option from the menu, and paste the code in.


--
HTH

Bob

(there's no email, no snail mail, but somewhere should be gmail in my addy)
 
N

NPell

Private Sub Worksheet_Change(ByVal Target As Range)
Const WS_RANGE As String = "K:K"     '<== change to suit

    On Error GoTo ws_exit
    Application.EnableEvents = False

    If Not Intersect(Target, Me.Range(WS_RANGE)) Is Nothing Then
        With Target
            If .Value = "v" Then

                .Offset(0, 2).Value = Environ("Username")
            End If
        End With
    End If

ws_exit:
    Application.EnableEvents = True
End Sub

'This is worksheet event code, which means that it needs to be
'placed in the appropriate worksheet code module, not a standard
'code module. To do this, right-click on the sheet tab, select
'the View Code option from the menu, and paste the code in.

--
HTH

Bob

(there's no email, no snail mail, but somewhere should be gmail in my addy)
















- Show quoted text -

This should work, i can tell, but it doesnt.
Can i just ask where its drawing the Username information from, or if
i need to add more to the code?
 
N

NPell

This should work, i can tell, but it doesnt.
Can i just ask where its drawing the Username information from, or if
i need to add more to the code?- Hide quoted text -

- Show quoted text -

Oh, sorry, i didnt say thankyou!
I do appreciate you helping, Bob.
 
B

Bob Phillips

No problem.

It gets the username from the system login. In what way does it not work?

--
HTH

Bob

(there's no email, no snail mail, but somewhere should be gmail in my addy)

This should work, i can tell, but it doesnt.
Can i just ask where its drawing the Username information from, or if
i need to add more to the code?- Hide quoted text -

- Show quoted text -

Oh, sorry, i didnt say thankyou!
I do appreciate you helping, Bob.
 
N

NPell

No problem.

It gets the username from the system login. In what way does it not work?

--
HTH

Bob

(there's no email, no snail mail, but somewhere should be gmail in my addy)






Oh, sorry, i didnt say thankyou!
I do appreciate you helping, Bob.- Hide quoted text -

- Show quoted text -

Ah ok.

Well, It just doesnt show anything when i do put the "v" in cell in
Column K. It just seems as if it doesnt run or doesnt register.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top