+ Reply to Thread
Results 1 to 1 of 1

Name Organisation VBA / Macro Code

Hybrid View

  1. #1
    Registered User
    Join Date
    02-04-2009
    Location
    UK
    MS-Off Ver
    Excel 2003
    Posts
    3

    Name Organisation VBA / Macro Code

    Hey all,

    Right, I have a row of Title, Name, Telephone Number etc and what I want to do is organise the fields below these titles to appear in order (Mr first, Mrs second, Ms third, Miss last) but also, that it organises all the information within the corresponding fields as well. But I'm not sure how to link this VB code to my macro so when I click the button, it organises.

    I think I have my code ok, but I wouldn't be suprised if I went totally off mark here as VB isn't really my fort'e

    Code:

    Dim rowVa As Integer, colVa As String
    rowVa = Selection.Row
    colVa = Selection.Column
    colVa = GetExcelColumn(Selection.Column)
    If Cells(rowVa, colVa) = "Title" Then
    Range(colVa & "2", colVa & "5").Select
    ' here you can introduce a function to get the no of last cell and include it in place of 5
     
    Selection.Sort Key1:=Range(colVa & "2"), Order1:=xlAscending, Header:=xlGuess, _
    OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom, _
    DataOption1:=xlSortNormal
    End If
     
    End Sub
    Function GetExcelColumn(ByVal iCellNo As Integer) As String
    Dim iBeg, iEnd As Integer
     
    ' If 1-26, then this is an easy conversion
    If iCellNo < 27 Then
    GetExcelColumn = Chr$(iCellNo + 64)
    Else
    ' Now we have to account for AA-ZZ
    iBeg = iCellNo \ 26 ' Get the first letter
    iEnd = iCellNo Mod 26 ' Get the second letter
    If iEnd = 0 Then
    ' If iEnd is 0, then it is Z, which should be 26
    iEnd = 26
    '** you need to subtract 1 from the initial letter otherwise your lettering will be the next letter in the alphabet
     
    iBeg = iBeg - 1
    End If
    GetExcelColumn = Chr$(iBeg + 64) & Chr$(iEnd + 64)
    End If
    End Function
    Any suggestions greatly appreciated
    Last edited by VBA Noob; 02-06-2009 at 01:41 PM.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1