Name of column Headers

Eric Penfold

Active Member
Joined
Nov 19, 2021
Messages
424
Office Version
  1. 365
Platform
  1. Windows
  2. Mobile
I need to list the names of my headers I`ve attempted to but no success?
Here is the Header loop. It shows blank?
Many Thanks in advance

VBA Code:
    For Each X In Rows(1).Cells
        If X.Value = "" Then Exit For
        Y = Y + 1
        ReDim Preserve heading(i) As String
        heading(Y) = X.Value
    Next X

End With

VBA Code:
Sub vLookupAnotherWorkbook()

    Dim Src As Workbook
    Dim Des As Workbook
    Dim SASheet As Worksheet
    Dim PASheet As Worksheet
    Dim MBefore As Integer
    Dim MName As String
    Dim ColNames As Object
    Dim WSArray, i
    ReDim WSArray(1 To Sheets.Count)
    Dim heading() As String, X As Variant, Y as Variant
    Dim LRow As Long

   
    ReDim ColArray(1 To Columns.Count)
  
   
    Dim FileToOpen As Variant
  
   
    With Application
        .ScreenUpdating = False
        .EnableEvents = False
    End With

    FileToOpen = ("\\DC01\Company\PURCHASING\Forecasting\Brett Martin Template for Vlookup.xlsm")
    Workbooks.Open FileToOpen
    Set Src = Workbooks("Brett Martin Template for Vlookup.xlsm")
    Set Des = Workbooks("Brett Martin Forecast 2022.xlsm")
    Set SASheet = Src.Sheets("Sales Analysis")
    LRow = SASheet.Range("A1").CurrentRegion.Rows.Count


    MBefore = Format(DateAdd("m", -1, Date), "mm")
  
    MName = MonthName(MBefore)
   
    With Des
   
    For i = 1 To .Sheets.Count
    WSArray(i) = .Sheets(i).Name
    Next
   
    End With
   
   
    With SASheet
   
    For Each X In Rows(1).Cells
        If X.Value = "" Then Exit For
        Y = Y + 1
        ReDim Preserve heading(i) As String
        heading(Y) = x.Value
    Next x
       
    End With

   

    With Application
        .ScreenUpdating = True
        .EnableEvents = True
    End With
   
   
'  Workbooks("Src").Close _
'  SaveChanges:=False
 
     End Sub
 

Excel Facts

Will the fill handle fill 1, 2, 3?
Yes! Type 1 in a cell. Hold down Ctrl while you drag the fill handle.
If you mean the values in row 1, then that is what the code will do.
 
Upvote 0
The x needs to be a array of words not a single number
Capture.PNG
 
Upvote 0
X is not the array heading is.
 
Upvote 0
That's exactly what the code does.
 
Upvote 0
Glad we could help & thanks for the feedback.
 
Upvote 0

Forum statistics

Threads
1,215,231
Messages
6,123,754
Members
449,119
Latest member
moudenourd

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