+ Reply to Thread
Results 1 to 3 of 3

Get Column headers using VBA

Hybrid View

  1. #1
    Registered User
    Join Date
    05-04-2021
    Location
    India
    MS-Off Ver
    2019
    Posts
    37

    Get Column headers using VBA

    Hi is this possible to get column header name instead of column numeric value
    Column: " & x &
    using VBA in below sample code.


    Sub Loop_Column_Row()
        
        Dim lRow, lCol As Long
    
        'Counter
        Dim i As Integer
        'Find the last non-blank cell in row 1
        'This assumes that the first 5 row has column headers
        lCol = Cells(6, Columns.Count).End(xlToLeft).Column
        i = 1
        
        'Loop through columns
        For x = 1 To lCol
            'Find the last non-blank cell in the column
            lRow = Cells(Rows.Count, x).End(xlUp).Row
        
            'Loop through rows
            'Start from row 2 as row 1 is the row with headers
            For y = 6 To lRow
                If Cells(y, x) = "" Then
                    'Write in column A of Sheet3
                    ThisWorkbook.Worksheets("Sheet3").Range("A" & i).Value = "Cell in Row: " & y & " Column: " & x & " is empty"
                    i = i + 1
                End If
            Next y
        Next x
      
    End Sub

  2. #2
    Forum Guru Sintek's Avatar
    Join Date
    12-04-2015
    Location
    Cape Town
    MS-Off Ver
    2013 | 2019 | 2021
    Posts
    15,027

    Re: Get Column headers using VBA

    "Column: " & Split(Cells(1, x).Address, "$")(1)
    Or did you mean the Header in Row 1 of said Column...
    "Column: " & Cells(1, x)
    Last edited by Sintek; 05-07-2021 at 09:30 AM.
    Good Luck...
    I don't presume to know what I am doing, however, just like you, I too started somewhere...
    One-day, One-problem at a time!!!
    If you feel I have helped, please click on the [★ Add Reputation] to left of post window...
    Also....Add a comment if you like!!!!
    And remember...Mark Thread as Solved...
    Excel Forum Rocks!!!

  3. #3
    Forum Guru HaHoBe's Avatar
    Join Date
    02-19-2005
    Location
    Hamburg, Germany
    MS-Off Ver
    work: 2016 on Win10 (notebook), private: 365 on Win11 (desktop), 2019 on Win11 (notebook)
    Posts
    8,199

    Re: Get Column headers using VBA

    Hi mailtoashok13,

    why not simply use

    ThisWorkbook.Worksheets("Sheet3").Range("A" & i).Value = "Cell " & Cells(y, x).Address(0 ,0) & " is empty"
    Ciao,
    Holger
    Use Code-Tags for showing your code: [code] Your Code here [/code]
    Please mark your question Solved if there has been offered a solution that works fine for you

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. [SOLVED] Extract multiple row headers and column headers if criteria is met in multiple columns
    By PaulM100 in forum Excel Formulas & Functions
    Replies: 11
    Last Post: 09-20-2019, 04:56 AM
  2. Filter Data Set using Row Headers in lieu of Column Headers
    By bsnell in forum Excel Formulas & Functions
    Replies: 0
    Last Post: 07-30-2019, 11:43 AM
  3. [SOLVED] Copy multiple column and paste in the template based on column headers VBA
    By rakul_rakul in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 09-24-2018, 01:23 PM
  4. VBA Excel: Copy/Paste a column range to another sheet IF column headers match
    By hwatson86 in forum Excel Programming / VBA / Macros
    Replies: 16
    Last Post: 06-07-2016, 08:05 AM
  5. Replies: 1
    Last Post: 02-03-2016, 02:33 AM
  6. [SOLVED] listbox with column headers as a specific sheet column headers
    By ANDREAAS in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 06-07-2014, 04:40 AM
  7. Replies: 2
    Last Post: 05-09-2012, 01:30 PM

Tags for this Thread

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1