PDA

View Full Version : Assigning Headers



visualnewbie
08-04-2014, 12:00 PM
I have a table that needs headers assigned to it. I have attached a copy of 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.




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

ranman256
08-04-2014, 01:24 PM
Wouldnt you just have ALL the col. headers on a sheet,
copy the row,
goto target sheet -1st row , insert paste?

Why do all this looping?

visualnewbie
08-05-2014, 05:42 AM
Because those headers will not be the same each time

snb
08-05-2014, 09:02 AM
Start removing all merged cells; VBA doesn't like them.
An xlsx file can't contain macros. Your question is about macros. Posting an xlsb or xlsm file would be more obvious then.

marreco
08-05-2014, 10:51 AM
Hi.
You need show your
Cross-post
http://www.excelforum.com/excel-programming-vba-macros/1028961-assigning-headers-to-columns.html

visualnewbie
08-05-2014, 11:07 AM
Thank you snb you are such a great help next time I'll come to you if I care about your opinion.