Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Rhinorhino on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Creating Excel Translation "Table"

Status
Not open for further replies.

BlueScr33n

Instructor
Joined
Feb 10, 2003
Messages
78
Location
US
Would like to automate a process of coding data in an excel sheet prior to importing it into another program. Thus far, it's been a manual process of:
1. For each column containing data, insert a column before it.

2. In column A only, insert the <Tr> for each of the Rows that contain data.

3. In the remaining blank columns insert <Tc> for each of the Rows that contain data.

Something like this:
heading 1 heading 2 heading 3 heading 4 heading 5
data 1 data 2 data 3 data 4 data 5
data 1 data 2 data 3 data 4 data 5

<Tr> heading 1 <Tc> heading 2 <Tc> heading 3 <Tc> heading 4 <Tc> heading 5
<Tr> data 1 <Tc> data 2 <Tc> data 3 <Tc> data 4 <Tc> data 5
<Tr> data 1 <Tc> data 2 <Tc> data 3 <Tc> data 4 <Tc> data 5


Any help would be appreciated, thanks for reading!
 
If you do it manually while recording a macro, it will be automated for the next time you need to do it ( typing the code will take as long as doing it manually once).
So go to the menu Tools>Macro>record new macro
Give the macro a name and choose where to save it ( the personal.xls file is convenient).
Insert your blank columns, formula's, etc.. and then close the macro.
Whenvere you need it, just run it ( you can add a button on a toolbar or a menu item, as you wish)
[2thumbsup]
 
Have been doing it manually, the reason I wanted to automate it was because the tables I'm working on are of varying widths (# of columns) and depths (# of rows).
 
Just in case this comes up again (here's the answer):

Sub TableCols()

LastCol = Cells(1, 256).End(xlToLeft).Column

Do
Cells(1, LastCol).Select
ActiveCell.EntireColumn.Insert
If LastCol = 1 Then Exit Do
LastCol = ActiveCell.Offset(0, -1).Column
Loop

LastCol = Cells(1, 256).End(xlToLeft).Column

For i = 2 To LastCol Step 2
For Each c In Range(Cells(1, i), Cells(Rows.Count, i).End(xlUp))
If Not IsEmpty(c) Then
If i = 2 Then
c.Offset(0, -1) = &quot;<Tr>&quot;
Else
c.Offset(0, -1) = &quot;<Tc>&quot;
End If
End If
Next
Next
ActiveWorkbook.SaveAs FileName:=&quot;p:\To Xyvision\TestTom.xls&quot;
End Sub
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top