Consulting

Results 1 to 3 of 3

Thread: UI and Cell Event Routines?

  1. #1
    VBAX Regular
    Joined
    May 2009
    Location
    Johannesburg
    Posts
    69
    Location

    UI and Cell Event Routines?

    Hi All,

    I have a formatted worksheet with a number of rows with categorised information in these rows (accross several cols). In Col "A" I have a little 'code' and I want the row number to change based on this 'code' as entered by the user. That is, I want the entire row to Cut/Paste to a different location on the same Sheet, based on the category value typed into Columb "A". This Sub must fire every time the user clicks out of the cell.

    As such, I want to know if there is some sort of Cell_OnExit() routine I can call to make this happen every the user clicks out of Cell(x, "A")?
    Deyken
    DeezineTek
    South Africa

  2. #2
    VBAX Guru mancubus's Avatar
    Joined
    Dec 2010
    Location
    "Where I lay my head is home" :D
    Posts
    2,644
    hi.

    [VBA]
    Private Sub Worksheet_SelectionChange(ByVal Target As Range)
    'adopted from:
    'http://www.ozgrid.com/forum/showthread.php?t=36223

    Dim strName As String
    Dim rngTemp As Range

    strName = "'" & Target.Parent.Name & "'!lastcell"
    With ActiveWorkbook
    On Error Resume Next
    Set rngTemp = .Names(strName).RefersToRange
    On Error GoTo 0
    If Not rngTemp Is Nothing Then
    .Names(strName).RefersTo = "='" & Target.Parent.Name & "'!" & Target.Address
    If rngTemp.Column = 1 And Target.Column <> 1 Then
    'your cut/paste code goes here
    'your cut/paste code goes here
    'your cut/paste code goes here
    'your cut/paste code goes here
    End If
    Else
    .Names.Add Name:=strName, RefersTo:="='" & Target.Parent.Name & "'!" & Target.Address
    End If
    End With

    End Sub
    [/VBA]
    PLS DO NOT PM; OPEN A THREAD INSTEAD!!!

    1) Posting Code
    [CODE]PasteYourCodeHere[/CODE]
    (or paste your code, select it, click # button)

    2) Uploading File(s)
    Go Advanced / Attachments - Manage Attachments / Add Files / Select Files / Select the file(s) (multiple files can be selected while holding Ctrl key) / Upload Files / Done
    Replace company specific / sensitive / confidential data. Include so many rows and sheets etc in the uploaded workbook to enable the helpers visualize the data and table structure. Helpers do not need the entire workbook.

    3) Testing the Codes
    always back up your files before testing the codes.

    4) Marking the Thread as Solved
    from Thread Tools (on the top right corner, above the first message)

  3. #3
    VBAX Master Aflatoon's Avatar
    Joined
    Sep 2009
    Location
    UK
    Posts
    1,720
    Location
    I would suggest a worksheet_change event since you presumably want the code triggered when you change a cell in column A rather than every time you select a different cell.
    Be as you wish to seem

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •