View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.worksheet.functions
troy@eXL troy@eXL is offline
external usenet poster
 
Posts: 7
Default Column subtractions

On Oct 4, 9:30 am, Mike Darrington
wrote:
I have an input box that asks the user to input a new column for a range to
set the print area. I have on sheet that has one less column than the rest.
Is there a way to have it take off on column?

Here is what I have

newcolumn = InputBox("New Column", "New Column for Trends")

User puts in AJ

On one sheet I only want it to go to AI is there a way to do this without
asking another question?


Hi Mike,

I guess the simplest solution is to insert a column in the worksheet
so it has the same number of columns as all the other sheets and then
hide the new column. But if that's not an option...

You can set up an array containing the column indices (letters) either
in your code or in a worksheet somewhere (probably hidden) so that you
can substitute AI for AJ when required.

eg if array is in a worksheet simply have a one column array that
starts with A in the first cell then B in next cell down then C then D
etc. Name your array and reference it in your code when setting the
print area for the unusual sheet. Assuming you've named it
"columnArray" and it's in the first worksheet your code could look
something like this:

With Worksheets(1).Range("columnArray")
Set c = .Find(newcolumn, LookIn:=xlValues)
If Not c Is Nothing Then
firstAddress = c.Address
Do
foundAddress = c.Address
prevCol = Range(foundAddress).Offset(-1, 0).Value
Set c = .FindNext(c)
Loop While Not c Is Nothing And c.Address < firstAddress
End If
End With

This will search through the array until it finds AJ (or whatever the
value of newcolumn is) then assign the value of the cell above (which
has the previous column index in it) to prevCol. Use prevCol when
setting the print area for the unusual sheet.

Hope this makes sense and helps!

cheers,
t.