View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Neil[_11_] Neil[_11_] is offline
external usenet poster
 
Posts: 43
Default Macro to insert column

Colin,

This will give you the last used column in Row 1

Dim lastColumn As Long
lastColumn = Cells(1, 100).End(xlToLeft).Column
MsgBox lastColumn

Neil

"Colin Foster" wrote in message
...
Hello,
I have a worksheet which records special prices for certain customers, all
other customers using a fixed price on the main worksheet within the
workbook.

If a customer now needs to be included in those with the special price,

then
their details have to be included in the Special Prices sheet.

The way that I do this at present is to inseert a column, add in some
references to ensure that they are included in the various lookup tables

and
then input their specific information.

I now want someone else to be able to do this for me, so need to automate
the insertion of the columns and setting up of the references for the
lookups. I have been able to do this via a macro, however, there is one

part
that I am having a problem with and that is the insertion of the column.

If
I record the macro, then it lets me insert in (say) column "P", however,
next time I will want this to be column "Q". Is there a way of getting

Excel
to either prompt for a column reference (in a similar way to a parameter
query in Access), or is there an easy way to find the last used column and
then move back one before inserting?

Regards
Colin Foster