VBA Code creating a title for columns that are not blank

peter_z

Board Regular
Joined
Feb 27, 2011
Messages
87
Hey Guys, I'm a bit stuck on this one.
Anyone have any code or any idea how to write a piece of code which will look down a column and then if there are some cells with letters and numbers return a title or if there are no cells then return no title.

Also say column 1 has something title would be -> Field 1
Column 2 has something title would be -> Field 2
Column 3 onwards has nothing -> stop titles

Cheers for your help in advance :)
 

Excel Facts

When they said...
When they said you are going to "Excel at life", they meant you "will be doing Excel your whole life".
try:
Code:
Sub blah()
FieldNo = 1
For Each colm In ActiveSheet.UsedRange.Offset(1).Columns
    If Application.CountA(colm) > 0 Then
        If IsEmpty(Cells(1, colm.Column)) Then
            Cells(1, colm.Column).Value = "Field " & FieldNo
            FieldNo = FieldNo + 1
        Else
            MsgBox "Cell " & Cells(1, colm.Column).Address(False, False) & " already appears to have something in it, so no new header added."
        End If
    End If
Next colm
End Sub
 
Upvote 0

Forum statistics

Threads
1,224,564
Messages
6,179,544
Members
452,925
Latest member
duyvmex

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