Assigning Headers

visualnewbie09

New Member
Joined
Jul 23, 2014
Messages
16
I have a table that needs headers assigned to it. I have copied a link to view the example spreadsheets. The first sheet has the table and the second sheet has the headers. The code is designed to go to sheet 1 see what file name is being used and assign the header to the file name. Each file has two columns of data for Location 1 and Location 2, but have the same file name so it's assigns the first header, but ignores the second header. If someone could fix so it so that it assigns it by the file name and also if it's Location 1 data or Location 2 data.

https://docs.google.com/spreadsheets/d/1QDcX-smS8Wp-ryWw8NNrjiPU1vI9E-WeSYRiroztJHk/edit?usp=sharing

Code:
Sub FindHeaders()
Dim iRowH, iColH, iRowD, iColD As Integer
Dim strHeader, strData, strTitle As String

iRowD = 3
iColD = 2

iRowH = 2
iColH = 1

Sheets("Sheet1").Activate

Do Until Len(Cells(iRowD, iColD).Value) < 1

    strData = Cells(iRowD, iColD).Value
    Sheets("Sheet 2").Activate
    Do Until Len(Cells(iRowH, iColH).Value) < 1
        strHeader = Cells(iRowH, iColH).Value
        If strData = strHeader Then GoTo HeaderFound
        iRowH = iRowH + 2
    Loop
    'Header Data not Found
HeaderFound:

strTitle = Cells(iRowH - 1, iColH).Value
Sheets("Sheet 1").Activate
Cells(iRowD - 2, iColD).Value = strTitle
    
iColD = iColD + 3
    
Loop



End Sub
 

Excel Facts

Highlight Duplicates
Home, Conditional Formatting, Highlight Cells, Duplicate records, OK to add pink formatting to any duplicates in selected range.

Forum statistics

Threads
1,223,248
Messages
6,171,021
Members
452,374
Latest member
keccles

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