Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 14
Default Number and names of courses may change later

I'm using Excel 2010 and I have three company course names that I must add to a spreadsheet and I must do this operation routinely. I want the operation to move to the right in the spreadsheet and find the first available and empty column and then enter the course name, move right, enter another course name, etc. Here is the code that I'm using and it does work.

Code:
'Enter the three Course names at the end of the spreadsheet
    Selection.End(xlToRight).Select
    Range("Q1").Select
    ActiveCell.FormulaR1C1 = "Social Styles"
    Range("R1").Select
    ActiveCell.FormulaR1C1 = "Adaptive Leadership"
    Range("S1").Select
    ActiveCell.FormulaR1C1 = "Leading Virtually"
    Range("Q1:S1").Select
    Range("S1").Activate
    Selection.Font.Bold = True
    Cells.Columns.AutoFit
Here's the problem. Although this code works (thanks Macro recorder), it limits me to three courses with the names above. Next year it may be four, or five courses and they will be different names. I'm thinking that what I need is the ability to set variables as the course names then loop through those variables inserting their names in the proper places. This would allow me in the future to change only the variable names and everything would fall into place. Am I thinking about this correctly? Can anyone give me an idea what the code may look like. I do understand variables and arrays but I can't seem to piece it all together in my mind. Many thanks.




  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,872
Default Number and names of courses may change later

Hi John,

I forgot font.bold and autofit:

Sub Test()
Dim i As Integer
Dim FECol As Long
Dim NamesArr As Variant

NamesArr = Array("Social Styles", "Adaptive Leadership", _
"Leading Virtually")
FECol = Cells(1, Columns.Count).End(xlToLeft).Column + 1

For i = 0 To UBound(NamesArr)
With Cells(1, FECol + i)
.Value = NamesArr(i)
.Font.Bold = True
.EntireColumn.AutoFit
End With
Next
End Sub


Regards
Claus Busch
--
Win XP PRof SP2 / Vista Ultimate SP2
Office 2003 SP2 /2007 Ultimate SP2
  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 14
Default Number and names of courses may change later

Your code worked flawlessly and helped me understand how to do it. Thank you very much.
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
How do I change Column names (a,b,c to Name, Number) cmw410 Excel Worksheet Functions 2 March 4th 10 03:39 PM
university courses in VBA Maxx[_2_] Excel Programming 3 April 25th 08 04:34 PM
Dowload Courses to my PC gab Excel Discussion (Misc queries) 0 February 26th 06 02:57 PM
Students and Courses asante_za Excel Programming 1 January 12th 06 06:18 PM
Change names of files in a folder to match names in Excel Column saybut Excel Programming 4 February 9th 04 06:26 PM


All times are GMT +1. The time now is 06:04 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"