Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Conditional column selection

set rng = Range("B2").End(xltoRight).offset(0,-1)
if rng.HasFormula then
set rng = rng.offset(0,1)
End if

General approach - adjust to your specific situation.

--
Regards,
Tom Ogilvy


"AG" wrote in message
...
I have a monthly spreadsheet setup such that columns A & B are text,

column C is January, column D is February, column E is March, BUT column F
are quarterly totals formulas and so on ending at column S which are year to
date totals formulas. Entries begin in row 2.

On occasion I need to overwrite the monthly entries.


If I want to overwrite the 2nd or 3rd month of a quarter, no problem, I

would use the End Method.

I'd select cell A2 and use the End Method
Range ("B2") .End(xlTo Right) .Select
And select the previous column.

I run into a problem when I want to overwrite the 1st month of a quarter's

entries as the End Method less 1 column to the left puts me in a quarterly
totals column.

How do I prevent overwriting any of the quarterly columns?

Thanks I advance.

Al



  #2   Report Post  
Posted to microsoft.public.excel.programming
AG AG is offline
external usenet poster
 
Posts: 54
Default Conditional column selection

Very clean; thanks.
The solution exposed me to an entire new set of tools!

Can I then declare the resultant column as a variable AND call/reference it to select other similar similarly setup sheets within the same workbook?

Such that:
set rng = Range("B2").End(xltoRight).offset(0,-1)
if rng.HasFormula then
set rng = rng.offset(0,1)
End if

Dim Acol As Range
Acol = ActiveCell.Column

€˜ do the required work and then

Sheets ("Sheet 2").Select
Acol.Select
€˜ do the required work


"Tom Ogilvy" wrote:

set rng = Range("B2").End(xltoRight).offset(0,-1)
if rng.HasFormula then
set rng = rng.offset(0,1)
End if

General approach - adjust to your specific situation.

--
Regards,
Tom Ogilvy


"AG" wrote in message
...
I have a monthly spreadsheet setup such that columns A & B are text,

column C is January, column D is February, column E is March, BUT column F
are quarterly totals formulas and so on ending at column S which are year to
date totals formulas. Entries begin in row 2.

On occasion I need to overwrite the monthly entries.


If I want to overwrite the 2nd or 3rd month of a quarter, no problem, I

would use the End Method.

I'd select cell A2 and use the End Method
Range ("B2") .End(xlTo Right) .Select
And select the previous column.

I run into a problem when I want to overwrite the 1st month of a quarter's

entries as the End Method less 1 column to the left puts me in a quarterly
totals column.

How do I prevent overwriting any of the quarterly columns?

Thanks I advance.

Al




  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Conditional column selection

a range is specific to the sheet it is on, so you would have to change your
code slightly

rng.select
Dim Acol As Long
Acol = ActiveCell.Column ' unless you select rng, it isn't the activecell.

' do the required work and then

Sheets ("Sheet 2").Select
cells(1, Acol).Select
' or Columns(Acol).Select ' if you want the whole column
' do the required work

all that said, I would try to learn not to select and activate

set rng1 = Worksheets("Sheet 2").Cells(1,Acol)

rng1.value = 100

would work from sheet1 as an example. Or just do it directly

Worksheets("Sheet 2").Cells(1,Acol).Value = 100
--
Regards,
Tom Ogilvy


"AG" wrote in message
...
Very clean; thanks.
The solution exposed me to an entire new set of tools!

Can I then declare the resultant column as a variable AND call/reference

it to select other similar similarly setup sheets within the same workbook?

Such that:
set rng = Range("B2").End(xltoRight).offset(0,-1)
if rng.HasFormula then
set rng = rng.offset(0,1)
End if

Dim Acol As Range
Acol = ActiveCell.Column

' do the required work and then

Sheets ("Sheet 2").Select
Acol.Select
' do the required work


"Tom Ogilvy" wrote:

set rng = Range("B2").End(xltoRight).offset(0,-1)
if rng.HasFormula then
set rng = rng.offset(0,1)
End if

General approach - adjust to your specific situation.

--
Regards,
Tom Ogilvy


"AG" wrote in message
...
I have a monthly spreadsheet setup such that columns A & B are text,

column C is January, column D is February, column E is March, BUT column

F
are quarterly totals formulas and so on ending at column S which are

year to
date totals formulas. Entries begin in row 2.

On occasion I need to overwrite the monthly entries.


If I want to overwrite the 2nd or 3rd month of a quarter, no problem,

I
would use the End Method.

I'd select cell A2 and use the End Method
Range ("B2") .End(xlTo Right) .Select
And select the previous column.

I run into a problem when I want to overwrite the 1st month of a

quarter's
entries as the End Method less 1 column to the left puts me in a

quarterly
totals column.

How do I prevent overwriting any of the quarterly columns?

Thanks I advance.

Al






Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Conditional Formating Based on Selection in a Combo Box adrian007uk Excel Discussion (Misc queries) 4 December 11th 09 08:54 AM
Conditional Selection [email protected] Excel Worksheet Functions 1 June 5th 07 03:00 AM
Formatting (conditional?) a drop down box selection Judithj Excel Discussion (Misc queries) 3 April 9th 07 09:28 PM
Conditional Formatting and selection Kristin N Excel Discussion (Misc queries) 2 September 15th 05 06:27 PM
Conditional selection of two column, csv file Will[_7_] Excel Programming 2 May 19th 04 02:51 PM


All times are GMT +1. The time now is 10:40 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"