Parse column number to letters

Flyingmeatball

Board Regular
Joined
Aug 15, 2007
Messages
65
I need to write a simple formula that will reference every 7th column on another worksheet. For example: my first cell should be something like =Otherpage!C1. The next sell will be =Otherpage!J1. I'd like to write a macro that outputs these formulas as a string, like "=Otherpage" & colnum(X) & "1". Does anyone know how I parse something like "colnum(x)" to "BA" column labels? I need the physical letter name.

Thanks!
 

Excel Facts

Did you know Excel offers Filter by Selection?
Add the AutoFilter icon to the Quick Access Toolbar. Select a cell containing Apple, click AutoFilter, and you will get all rows with Apple
Actually, you might not need the column letter.

If you were to create/write the formulas using R1C1 notation then you could use the column number.
 
Upvote 0
Well getting the column letter is the end goal. I can write a macro if i wanted just to move the column, but the point is to write a macro that will output "C, J Q" etc. Im writing this formula in another proprietary spreadsheet program, but it has a lot of the same formulas. I need my ending formula to enter into a physical cell to be "=somesheet!C1", then the next should be 7 columns away, so i need to parse a change of 7 columns into a change from C to J. Make sense?

Thanks!
 
Upvote 0
"... so i need to parse a change of 7 columns into a change from C to J."

not necessarily. In formula-land:

=INDEX($C$1:$AA$1,,COLUMN($A$1)+((COLUMN()-1)*7))

...in colA and copied across would return the values from c1, j1,q1 etc
 
Upvote 0
That may indeed work, but I need it to be much cleaner. I need my excel formula to be a simple cell reference. This will be going to a client, and they need to be able to trace the calc, which I'm pretty sure they won't be able to do with your formula. Here's the code I've been working with to make it an output...I just need to fill in that one line.

Sub parse()

Dim formulacol As Integer
Dim x As Integer
Dim output As String
Dim currentparse As String

x = 3


For formulacol = 1 To 50

'Parse integer x to currentparse (current column label)

output.Value = "=othersheet!" & currentparse & "1"
Cells(1, formulacol).Value = output

x = x + 7

Next formulacol

End Sub

thanks for your help!
 
Upvote 0
vba's not my thing, but I expect the form of the solution to be as above for the formula approach - i.e. iterate by position, not letter - then get the reference in the format you require by embedding the iterations in an address() or similar.
 
Upvote 0
Hi

Not sure I understood correctly but I think you want something like this:

Code:
Sub parse()
Dim formulacol As Long
Dim x As Long
 
x = 3
For formulacol = 1 To 50
    Cells(1, formulacol).Value = Worksheets("OtherSheet").Cells(1, x).Value
    x = x + 7
Next formulacol
End Sub
 
Upvote 0
Not quite, that formula I believe gives me the values stored in those cells. Basically, all i want is the letter label of every 7th column from A to IV. I want my outputs to go, C, J, Q, X, AE and so on.
 
Upvote 0
Ok.

This code writes every seventh column label starting from "C" in the first row of the current worksheet.

Since you said until IV I assumed you have a version of excel with 256 columns.

Code:
Sub parse()
Dim formulacol As Long
Dim x As Long
 
formulacol = 1
For x = 3 To 256 Step 7
    Cells(1, formulacol).Value = Split(Cells(1, x).Address, "$")(1)
    formulacol = formulacol + 1
Next x
End Sub
 
Upvote 0

Forum statistics

Threads
1,224,561
Messages
6,179,522
Members
452,923
Latest member
JackiG

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top