Get column numbers of first and last columns in selected ran

Visions_Fugitive

New Member
Joined
Apr 15, 2002
Messages
18
I have a macro that needs to loop through all the selected columns, performing an operation on each of them. I just need a way to get the numbers of the first and last columns.

firstCol = Selection.??????
lastCol = Selection.??????

For x = firstCol To lastCol

Columns(x).TextToColumns DataType:=xlDelimited, _
ConsecutiveDelimiter:=False, Space:=False

Next x


Thanks in advance.
This message was edited by Visions_Fugitive on 2002-04-16 14:39
This message was edited by Visions_Fugitive on 2002-04-16 14:39
 
On 2002-04-18 07:25, Abdc wrote:
For Al Chara's code, you need to Dim the LastCol and First Col As String (as opposed to Bertie Bagshot's code which is "dimmed" as Integer).

You are right. Sorry, mistype on my part. It should read:
Dim FirstCol As String, LastCol As String
 
Upvote 0

Excel Facts

Which came first: VisiCalc or Lotus 1-2-3?
Dan Bricklin and Bob Frankston debuted VisiCalc in 1979 as a Visible Calculator. Lotus 1-2-3 debuted in the early 1980's, from Mitch Kapor.
On 2002-04-18 07:34, nisht wrote:
sub firstlastcolumn ()
dim intfirstcolumn as integer
dim intlastcolumn as integer
dim i as integer
' you need to make selection now..

' or you can select current region

' currentregion.select

intfirstcolumn = Activecell.column
intlastcolumn = selection.column.count + intfirstcolumn

' you can step for to get operation by leaving one column or two column.
for i = intfirstcolumn to intlastcolumn

cells(1,i) = "Put your operation."

next i

end sub


ni****h desai
http://www.pexcel.com


Your code only works if the active cell happens to be in the first column of the selected range.
Bertie Bagshot's code (FirstCol = Selection(1, 1).Column) works regardless of the active cell location.
In any event, Visions_Fugitive has already said that his macro is working.
 
Upvote 0

Forum statistics

Threads
1,214,978
Messages
6,122,547
Members
449,089
Latest member
davidcom

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top