ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Discussion (Misc queries) (https://www.excelbanter.com/excel-discussion-misc-queries/)
-   -   macro that selects mulitple columns (https://www.excelbanter.com/excel-discussion-misc-queries/146512-macro-selects-mulitple-columns.html)

[email protected]

macro that selects mulitple columns
 
Hello you all,

I need a macro te select a couple of columns. The selection always
consists of column D to J. Now I want the macro to add a specific
column to this selection. The column is chosen by the user. It would
be nice if the user is promted a question which column should be added
to the selection, based on the values that are in row 2.

Example
In row 2 of columns K,L and M are the values:

K L M
Toyota Renault Ford

If the user selects Renault, column L has to be added to the
selection.

Would someone be so kind to create this?

Thanks in advance.

Bernd


Dave Peterson

macro that selects mulitple columns
 
Maybe...

Option Explicit
Sub testme()
Dim myRng As Range
Dim myCell As Range

Set myCell = Nothing
On Error Resume Next
Set myCell = Application.InputBox(Prompt:="Please click a cell", _
Type:=8).Cells(1)
On Error GoTo 0

If myCell Is Nothing Then
'user hit cancel, what should happen
Else
With ActiveSheet
Set myRng = Union(.Range("D:J"), _
.Range(myCell.Address).EntireColumn)
End With
myRng.Select
End If

End Sub


wrote:

Hello you all,

I need a macro te select a couple of columns. The selection always
consists of column D to J. Now I want the macro to add a specific
column to this selection. The column is chosen by the user. It would
be nice if the user is promted a question which column should be added
to the selection, based on the values that are in row 2.

Example
In row 2 of columns K,L and M are the values:

K L M
Toyota Renault Ford

If the user selects Renault, column L has to be added to the
selection.

Would someone be so kind to create this?

Thanks in advance.

Bernd


--

Dave Peterson


All times are GMT +1. The time now is 09:00 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com