View Single Post
  #6   Report Post  
Posted to microsoft.public.excel.programming
bernd bernd is offline
external usenet poster
 
Posts: 39
Default Macro to select multiple columns

I got the code working, but don't think it's user friendly. Right now
the column number should be given by the user.
I would prefer the letter of the column or even better a value that is
selected by some kind of listbox.
Someone?

Sub MultiRange()
Dim r1 As Range, r2 As Range, myMultiAreaRange As Range
Dim vResult As Variant
vResult = Application.InputBox( _
Prompt:="Number of columns to copy:", _
Title:="Copy Columns", _
Type:=1, _
Default:=1)
If vResult = False Then Exit Sub 'user cancelled
Application.Goto (Cells(1, vResult))
Set r1 = Range("D1:J1")
Set r2 = ActiveCell
Set myMultiAreaRange = Union(r1, r2)
myMultiAreaRange.EntireColumn.Select
End Sub