Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
Pat Pat is offline
external usenet poster
 
Posts: 122
Default Adding a new column/field

The following code locks data onto column IV. So whenever a column elsewhere
is deleted the data will not shift to IU.



Private Sub Worksheet_Change(ByVal Target As Range)
Const fixed_name = "lock_formula"
Const refer_str = "=Sheet1!$IV$1:$IV$800"
Dim rng As Range
Dim save_formula

If IsError(Evaluate(fixed_name)) Then
ActiveWorkbook.Names.Add Name:=CStr(fixed_name),
RefersTo:=CStr(refer_str)
Else
If CStr(ActiveWorkbook.Names(CStr(fixed_name)).Refers To) <
CStr(refer_str) Then
On Error GoTo CleanUp
Application.EnableEvents = False
Set rng = Evaluate(fixed_name)
save_formula = rng.Formula
rng.Value = ""
Set rng = Range(CStr(refer_str))
rng.Formula = save_formula
ActiveWorkbook.Names(CStr(fixed_name)).RefersTo =
CStr(refer_str)
Else
'do nothing
End If
End If

CleanUp:
Application.EnableEvents = True
End Sub


What if I want to add a column somewhere on the sheet?

I could first delete an unused column somewhere on the sheet, but because
the code behind the sheet is to prevent the shift of data to field IU I am
therefore unable to add a new column/field.

How can I retain the code but also allow the addition of a new column/field?

Thanks if you are able to help.
Pat


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,885
Default Adding a new column/field

Pat wrote:
What if I want to add a column somewhere on the sheet?

I could first delete an unused column somewhere on the sheet, but
because the code behind the sheet is to prevent the shift of data to
field IU I am therefore unable to add a new column/field.

How can I retain the code but also allow the addition of a new
column/field?

Thanks if you are able to help.
Pat


Hi Pat
you should be able to add a new column. What kind of error did you get

Frank
  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Adding a new column/field

Only solution I can think of is to put your formulas on a second sheet
(possibly hidden) and rebuild your formulas from there (unless the formula
is really a single formula that can be multicell entered (ctrl+Enter). In
that case, you could just put the formula in the code.

Also, the code would have to be modified to search for a unique identifier
in the formula rather than relying on a named range.

Any of that sound appealing?

--
Regards,
Tom Ogilvy

"Pat" wrote in message
...
The following code locks data onto column IV. So whenever a column

elsewhere
is deleted the data will not shift to IU.



Private Sub Worksheet_Change(ByVal Target As Range)
Const fixed_name = "lock_formula"
Const refer_str = "=Sheet1!$IV$1:$IV$800"
Dim rng As Range
Dim save_formula

If IsError(Evaluate(fixed_name)) Then
ActiveWorkbook.Names.Add Name:=CStr(fixed_name),
RefersTo:=CStr(refer_str)
Else
If CStr(ActiveWorkbook.Names(CStr(fixed_name)).Refers To) <
CStr(refer_str) Then
On Error GoTo CleanUp
Application.EnableEvents = False
Set rng = Evaluate(fixed_name)
save_formula = rng.Formula
rng.Value = ""
Set rng = Range(CStr(refer_str))
rng.Formula = save_formula
ActiveWorkbook.Names(CStr(fixed_name)).RefersTo =
CStr(refer_str)
Else
'do nothing
End If
End If

CleanUp:
Application.EnableEvents = True
End Sub


What if I want to add a column somewhere on the sheet?

I could first delete an unused column somewhere on the sheet, but because
the code behind the sheet is to prevent the shift of data to field IU I am
therefore unable to add a new column/field.

How can I retain the code but also allow the addition of a new

column/field?

Thanks if you are able to help.
Pat




  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Adding a new column/field

New column would force data in IV off the page and screw up your name
redefinition would it not?


refersto: =Ref#
--
Regards,
Tom Ogilvy

"Frank Kabel" wrote in message
...
Pat wrote:
What if I want to add a column somewhere on the sheet?

I could first delete an unused column somewhere on the sheet, but
because the code behind the sheet is to prevent the shift of data to
field IU I am therefore unable to add a new column/field.

How can I retain the code but also allow the addition of a new
column/field?

Thanks if you are able to help.
Pat


Hi Pat
you should be able to add a new column. What kind of error did you get

Frank



  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,885
Default Adding a new column/field

Tom Ogilvy wrote:
New column would force data in IV off the page and screw up your name
redefinition would it not?


refersto: =Ref#


correct. My problem with this issue is I think in total it is creating
more and more overhead :-). i'm still not convinced that this is all
rquired. But it is a nice excercise to 'lock' cells :-)

Regards
Frank



  #6   Report Post  
Posted to microsoft.public.excel.programming
Pat Pat is offline
external usenet poster
 
Posts: 122
Default Adding a new column/field

Hello gentlemen

An interesting discussion. I think your suggestion Tom would be like
building a Rolls Royce of a sheet :-)
I am not so sure if it would be worth going to that trouble and maybe
screw up the original sheet in the process.

Thanks anyway for the suggestion.

regards
Pat

"Tom Ogilvy" wrote in message
...
Only solution I can think of is to put your formulas on a second sheet
(possibly hidden) and rebuild your formulas from there (unless the formula
is really a single formula that can be multicell entered (ctrl+Enter). In
that case, you could just put the formula in the code.

Also, the code would have to be modified to search for a unique identifier
in the formula rather than relying on a named range.

Any of that sound appealing?

--
Regards,
Tom Ogilvy

"Pat" wrote in message
...
The following code locks data onto column IV. So whenever a column

elsewhere
is deleted the data will not shift to IU.



Private Sub Worksheet_Change(ByVal Target As Range)
Const fixed_name = "lock_formula"
Const refer_str = "=Sheet1!$IV$1:$IV$800"
Dim rng As Range
Dim save_formula

If IsError(Evaluate(fixed_name)) Then
ActiveWorkbook.Names.Add Name:=CStr(fixed_name),
RefersTo:=CStr(refer_str)
Else
If CStr(ActiveWorkbook.Names(CStr(fixed_name)).Refers To) <
CStr(refer_str) Then
On Error GoTo CleanUp
Application.EnableEvents = False
Set rng = Evaluate(fixed_name)
save_formula = rng.Formula
rng.Value = ""
Set rng = Range(CStr(refer_str))
rng.Formula = save_formula
ActiveWorkbook.Names(CStr(fixed_name)).RefersTo =
CStr(refer_str)
Else
'do nothing
End If
End If

CleanUp:
Application.EnableEvents = True
End Sub


What if I want to add a column somewhere on the sheet?

I could first delete an unused column somewhere on the sheet, but

because
the code behind the sheet is to prevent the shift of data to field IU I

am
therefore unable to add a new column/field.

How can I retain the code but also allow the addition of a new

column/field?

Thanks if you are able to help.
Pat






  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Adding a new column/field

Actually, you only need the cells of interest on this "hidden" sheet.

--
Regards,
Tom Ogilvy

"Pat" wrote in message
...
Hello gentlemen

An interesting discussion. I think your suggestion Tom would be like
building a Rolls Royce of a sheet :-)
I am not so sure if it would be worth going to that trouble and maybe
screw up the original sheet in the process.

Thanks anyway for the suggestion.

regards
Pat

"Tom Ogilvy" wrote in message
...
Only solution I can think of is to put your formulas on a second sheet
(possibly hidden) and rebuild your formulas from there (unless the

formula
is really a single formula that can be multicell entered (ctrl+Enter).

In
that case, you could just put the formula in the code.

Also, the code would have to be modified to search for a unique

identifier
in the formula rather than relying on a named range.

Any of that sound appealing?

--
Regards,
Tom Ogilvy

"Pat" wrote in message
...
The following code locks data onto column IV. So whenever a column

elsewhere
is deleted the data will not shift to IU.



Private Sub Worksheet_Change(ByVal Target As Range)
Const fixed_name = "lock_formula"
Const refer_str = "=Sheet1!$IV$1:$IV$800"
Dim rng As Range
Dim save_formula

If IsError(Evaluate(fixed_name)) Then
ActiveWorkbook.Names.Add Name:=CStr(fixed_name),
RefersTo:=CStr(refer_str)
Else
If CStr(ActiveWorkbook.Names(CStr(fixed_name)).Refers To) <
CStr(refer_str) Then
On Error GoTo CleanUp
Application.EnableEvents = False
Set rng = Evaluate(fixed_name)
save_formula = rng.Formula
rng.Value = ""
Set rng = Range(CStr(refer_str))
rng.Formula = save_formula
ActiveWorkbook.Names(CStr(fixed_name)).RefersTo =
CStr(refer_str)
Else
'do nothing
End If
End If

CleanUp:
Application.EnableEvents = True
End Sub


What if I want to add a column somewhere on the sheet?

I could first delete an unused column somewhere on the sheet, but

because
the code behind the sheet is to prevent the shift of data to field IU

I
am
therefore unable to add a new column/field.

How can I retain the code but also allow the addition of a new

column/field?

Thanks if you are able to help.
Pat








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
Adding Text to Calculated Field RoadKill Excel Worksheet Functions 4 February 22nd 08 10:43 PM
Adding two field into Pivot Table IF Statement[_2_] Excel Discussion (Misc queries) 0 November 21st 07 05:12 PM
Adding a hylerlink to a text field PSULionRP Excel Discussion (Misc queries) 0 September 13th 07 09:08 PM
Adding a Background to a date in a field ajnw15035 Excel Discussion (Misc queries) 2 February 23rd 07 01:53 PM
Adding spaces to a text field Jason Trolian Excel Programming 2 December 1st 03 04:26 PM


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

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

About Us

"It's about Microsoft Excel"