Consulting

Results 1 to 6 of 6

Thread: get letter of the active column

  1. #1

    get letter of the active column

    Hi VBA gurus,

    Can someone help me please? I am stuck with this but temporarily use hardcode letter "F" of the column of the selected range. Any help is very very much appreciated. Thanks a million!

    Dim finalRow As Long
    finalRow = Sheets(2).Range("A65536").End(xlUp).Row
    Rows("1:2").Select
        Selection.Find(What:="PartNumber").Activate
        Selection.Copy
        Sheets(2).Range(ActiveCell.Address & ":F" & finalRow).Copy _      
                  Sheets(1).Range("IV1").End(xlToLeft).Offset(0, 1)

  2. #2
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    [vba]

    Sheets(2).Range(ActiveCell.Address, Sheets(2).Cells(finalRow, Activecell.Column)).Copy _
    Sheets(1).Range("IV1").End(xlToLeft).Offset(0, 1)
    [/vba]
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  3. #3
    Knowledge Base Approver VBAX Master Oorang's Avatar
    Joined
    Jan 2007
    Posts
    1,135
    Location
    Try This:
    [VBA]Public Sub Test()
    VBA.MsgBox ColumnLetter(ActiveCell.Column)
    End Sub
    Public Function ColumnLetter(ColumnNumber As Long) As String
    Const lngOffset_c As Long = 64
    ColumnLetter = VBA.Chr$(ColumnNumber + lngOffset_c)
    End Function[/VBA]
    Or you could switch from "range" to the "cells" syntax which allows you to use numeric row/column reference. (My own preference.)
    [VBA]Public Sub Test()
    Dim ws As Excel.Worksheet
    Set ws = Excel.ActiveSheet
    ws.Cells(1, 2).Value = "Foo"
    End Sub[/VBA]
    Cordially,
    Aaron



    Keep Our Board Clean!
    • Please Mark your thread "Solved" if you get an acceptable response (under thread tools).
    • Enclose your code in VBA tags then it will be formatted as per the VBIDE to improve readability.

  4. #4
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    Perhaps better

    [vba]

    Dim finalRow As Long
    With Sheets(2)
    finalRow = .Range("A" & .Rows.Count).End(xlUp).Row
    .Rows("1:2").Find(What:="PartNumber").Activate
    Selection.Copy
    .Range(ActiveCell.Address).Resize(finalRow - ActiveCell.Row + 1).Copy _
    Sheets(1).Cells(1, .Columns.Count).End(xlToLeft).Offset(0, 1)
    End With
    [/vba]
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  5. #5
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    Quote Originally Posted by Oorang
    Try This:
    [VBA]Public Sub Test()
    VBA.MsgBox ColumnLetter(ActiveCell.Column)
    End Sub
    Public Function ColumnLetter(ColumnNumber As Long) As String
    Const lngOffset_c As Long = 64
    ColumnLetter = VBA.Chr$(ColumnNumber + lngOffset_c)
    End Function[/VBA]
    [vba]

    Public Sub Test()
    VBA.MsgBox ColumnLetter(Range("AA1").Column)
    End Sub
    [/vba]
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  6. #6
    wow! you guys'r gorgeous. Thanks so much.

Posting Permissions

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