How to name sheets

philky001

Board Regular
Joined
Jun 8, 2005
Messages
129
HI I have a program that is programatically created sheets based on the text file input.
I need to name the sheets based on the patient name though. Currently it is just sheet1,2 etc.
I am using C# but how would you do this in C# or VBA or other language?
 

Excel Facts

Excel Can Read to You
Customize Quick Access Toolbar. From All Commands, add Speak Cells or Speak Cells on Enter to QAT. Select cells. Press Speak Cells.
Hello

Where do we find the information regarding how to name the sheets?

Is it in the same file?
 
Upvote 0
Where does the patient name come from?

Once you have that there are various ways you could name the sheets.

Which one to use might depend on how the sheets are created and which language you are using.

Here's one example in VBA.
Code:
Set wsPatient =ThisWorkbook.Worksheets.Add

wsPatient.Name = "ThePatientName"
Obviously you would have a variable for the name rather than a hard-coded value.
 
Upvote 0
yes the data from the text file looks like this: so you can look for resident name in c# we have this: e if (line.Contains("RESIDENT NAME"))
{
patient .ResidentName = line.Replace("RESIDENT NAME", "").Trim();
}

RESIDENT NAME AAB, SU W
ACCOUNT NUMBER 000001 @
ROOM NUMBER 102 -P
ADMISSION DATE 11-07-2010
AMOUNT REMITTED 0.00
BALANCE FORWARD OPENING BALANCE 0.00
TRANSACTIONS 8
TRANSACTION
TRANSACTION 07-31-09 07-03-09 668.00
TRANSACTION 06-30-09
Hello

Where do we find the information regarding how to name the sheets?

Is it in the same file?
 
Upvote 0
In C# you can use basically the same code as posted for VBA, just remove the Set and change the workbook reference.
 
Upvote 0

Forum statistics

Threads
1,224,811
Messages
6,181,081
Members
453,021
Latest member
Justyna P

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