Visual Basic within Excel

  • Thread starter visually challenged
  • Start date
V

visually challenged

Anyone know how to use visual basic to sort and print a
specified area of an excel worksheet? It is an ever
growing spreadsheet with adjustments made almost
constantly, so I need someway to have the macro know where
the last row is in order to sort the proper information.
Doing this sort manually is a pain in the backside.
 
F

Frank Kabel

Hi
try the following:
- start recording a macro
- select the entired columns
- sort the data
- print the data
- stop the recording

This should give you a good starting point
 
R

Rakesh

Better still...

Give your "range" a name (Insert, Name, Define, [name] - be sure you specify your range there). And every time you insert a row or column, always do it before the last one in the range - this way, your new row/col will be "picked up" without having to redefine the name-range. Finally, make sure that the macro makes reference to the name, not the range, ie. Application.Goto Reference:="[name]"

This is guaranteed to work all the time!
 
A

Anders Silven

Better still...

You can even make the named range adjust automatically. Debra Dalgleish has some
good instructions here:

http://www.contextures.com/xlNames01.html#Dynamic

Regards,
Anders Silven

Rakesh said:
Better still...

Give your "range" a name (Insert, Name, Define, [name] - be sure you specify
your range there). And every time you insert a row or column, always do it
before the last one in the range - this way, your new row/col will be "picked
up" without having to redefine the name-range. Finally, make sure that the macro
makes reference to the name, not the range, ie. Application.Goto
Reference:="[name]"
 
Top