Skip to main content
Announcements
Qlik Connect 2024! Seize endless possibilities! LEARN MORE
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

use names of excel

Suupose i have an excel sheets named FY11, FY12,FY13 ...In these excels i have columns named Jan Feb MAr Apr .. Now i want to rename these columns as JAn 11, Feb 11 .... based on the excel sheet names .. so how to do this stuff ..Can someone suggest me some idea ?

6 Replies
SunilChauhan
Champion
Champion

filebasename() will give you name without extention of excel

hope this helps

Sunil Chauhan
Not applicable
Author

Hi Sunil,

I tried this :- Jan as Jan&'-'&filebasename();

but it is not working

SunilChauhan
Champion
Champion

Jan as 'Jan'&'-'&filebasename();

or can you share sample file

Sunil Chauhan
Sokkorn
Master
Master

Hi,

Do you load data for specific sheet name or loop for all sheet in excel in one time?

If you load for specific sheet name; let say load only sheet FY11 then you can do this

     Load

          Months & 11,

     ......................

Regards,

Sokkorn

SunilChauhan
Champion
Champion

or you can try beloww code

Jan as Jan&'-'&right(filebasename(),2);

hope you required this

Sunil Chauhan
m_woolf
Master II
Master II

Once you have the workbook open (objWorkbook):

for i = 1 to objWorkbook.sheets.count

     strSheetname = objWorkbook.sheets(i).name   ' will give you the sheet name

     strYear = right(strSheetname,2)     ' will give you the year

' assuming your Jan column heading is in A1 and you have all 12 months

     for j = 1 to 12

          objWorkbook.sheets(i).cells(1,j).value = objWorkbook.sheets(i).cells(1,j).value & " " & strYear

     next

next