writing the column names in first row, based on the sheet name
Dim WS as excel.worksheet
for each WS in ThisWorkbook.worksheets
mytext = ""
if ws.name = "name1" then
myText = "Col"
elseif WS.name = "name2" then
myText = "some"
end if
if not mytext = "" then
for i = 1 to 10
ws.cells(1,i).value = mytext & i
next i
end if
Next WS
Select case would also work if you want to use that.
HTH,
Barb Reinhardt
"Sheela" wrote:
I am new to programming. This site has been very helpful for me. I am
learning as I am working.
I would need to write a macro to name columns based on the sheet name.
This code will run through all the sheets in the workbook and fill the first
row, based on the sheet name.
If sheetname name is name1 then column names are ( Col1, Col2, Col3)
( these will be written in the first row)
Else if sheetname is name2 then column names are (some1 some2)
Could someone please give me a sample template of code. I am thinking of
select case statement. But do not know how to write this in VBA code.
Thank you very much for you help in advance
sheela
|