visual basic automatically
The UK's Number 1 for Microsoft Office Training Add this page to your favourites/bookmarksBookmark page
 
View printable version of pagePrintable version
Plus One Google
Customer: Sign in
Delegate: Sign in
Trainer: Log in

Forum home » Delegate support and help forum » Microsoft Excel Training and help » Visual Basic - Automatically adding lines.

Visual Basic - Automatically adding lines.

resolvedResolved · Medium Priority · Version 2007

replyReply Fri 17 Sep 2010, 13:40Delegate Chris said...

Chris has attended:
Excel Advanced course

Visual Basic - Automatically adding lines.

Hi There

I am trying to create a macro which draws (via a vlookup) from an ever expanding list of variables. I have found I could add to the following code each time I wanted to add products to the list, but as there are circa 10,000 products, I would prefer an automated means - is this possible?

Example Code:

Sheets("Sheet2").Select
Range("C7").Select
ActiveCell.FormulaR1C1 = "Product"
Range("D7").Select
ActiveCell.FormulaR1C1 = "Cycle"
Range("C8").Select
ActiveCell.FormulaR1C1 = "Sausage"
Range("D8").Select
ActiveCell.FormulaR1C1 = "D"
Range("C9").Select
ActiveCell.FormulaR1C1 = "Egg"
Range("D9").Select
ActiveCell.FormulaR1C1 = "D"
Range("C10").Select
ActiveCell.FormulaR1C1 = "Potato"
Range("D10").Select
ActiveCell.FormulaR1C1 = "A"
Range("C11").Select
ActiveCell.FormulaR1C1 = "Chicken"
Range("D11").Select
ActiveCell.FormulaR1C1 = "B"
Range("C12").Select
ActiveCell.FormulaR1C1 = "Lettuce"
Range("D12").Select
ActiveCell.FormulaR1C1 = "C"
Range("C13").Select
ActiveCell.FormulaR1C1 = "Chips"
Range("D13").Select
ActiveCell.FormulaR1C1 = "D"
Range("C14").Select
ActiveCell.FormulaR1C1 = "Burger"
Range("D14").Select
ActiveCell.FormulaR1C1 = "B"
Range("C15").Select
ActiveCell.FormulaR1C1 = "Sauce"
Range("D15").Select
ActiveCell.FormulaR1C1 = "C"
Range("F9").Select

Many thanks in advance

Chris


For upcoming training course dates see: Pricing & availability

replyReply Tue 21 Sep 2010, 11:33Trainer Anthony said...

RE: Visual Basic - Automatically adding lines.

Hi Chris, thanks for your query. You need to turn your list into a Dynamic Named Range and use that range name in your VLookup. Here's an explanation of dynamic named ranges.

http://www.ozgrid.com/Excel/DynamicRanges.htm

That should save you a lot of coding!

Hope this helps,

Anthony

Tue 28 Sep 2010: Automatically marked as resolved.

 

Please browse our web site to find out more about
excel computer training and other Microsoft training courses.

Excel tip:

Deleting a range of cells using the autofill handle

Firstly, select the range of cells for which you would like to clear the contents. Then drag the autofill handle to the the top left corner of the selection whilst holding down the shift key. Your selected contents should then be deleted.

View all Excel hints and tips


Microsoft Certified Partner Accredited Training Provider: Institute of IT Training Institute of Leadership and Management - Certified Courses Security Seal verified by visa, mastercard securecard