Logo 
Search:

MS Office Answers

Ask Question   UnAnswered
Home » Forum » MS Office       RSS Feeds
  Question Asked By: Steven Wood   on Jan 28 In MS Office Category.

  
Question Answered By: William Evans   on Jan 28

Can I assume that your dynamically  incremented formulas  are actually going
into adjacent columns (not adjacent rows)? I.e. if you copy / paste the
formulas to the other cells, does Excel get it right?

If so, you can simply use copy / paste from within your VBA to do the same
thing.

Alternately, you can use the R1C1 version of the formula, using relative
addressing, and simply insert the same formula in each adjacent (column)
cell. The relative addressing will do the job.

If, instead, you are putting the formula into consecutive rows, then copy /
paste and relative R1C1 will not do the job.

You could use absolute R1C1 formulas. It's easier to increment column
numbers than column  letters.

Or you can write a simple function that gives you the column letter from a
column number. Such as

Option Explicit

Public Function ColumnLetter(ColumnNumber As Integer) As String
Const ToAlpha = 64
Dim FirstPart As Integer: FirstPart = Int((ColumnNumber - 1) / 26)
Dim SecondPart As Integer: SecondPart = ((ColumnNumber - 1) Mod 26) + 1
If FirstPart = 0 Then
ColumnLetter = Chr(ToAlpha + SecondPart)
Else
ColumnLetter = Chr(ToAlpha + FirstPart) + Chr(ToAlpha + SecondPart)
End If
End Function

Share: 

 

This Question has 3 more answer(s). View Complete Question Thread

 
Didn't find what you were looking for? Find more on Get Column by number Or get search suggestion and latest updates.


Tagged: