padawan_IT
padawan_IT

Reputation: 106

Excel/VBA Filling a variable with current column-name

I am using Excel and creating a macro.

My macro so far finds the next empty column and stops there to fill stuff in. Then it creates a new sheet, referencing to the first sheet. Because I could get the Column-Number (Selection.Column) I could actually do what I wanted, but I had to use several if-clauses.

But if I could just get the Column-name (A, B, C, D, etc...), I could store it in a variable before I create the new sheet in the macro and then my references would be much easier.

Just in case I couldn't get my question across (English is my 4th language): If the cell B3 was selected, I want to store "B" in a variable.

Dim ColumnName As String
ColumnName = ?

Upvotes: 1

Views: 961

Answers (1)

SJR
SJR

Reputation: 23081

Here is one way

ColumnName = Split(ActiveCell.Address(1, 1), "$")(1)

Upvotes: 1

Related Questions