View Single Post
  #13   Report Post  
Posted to microsoft.public.excel.programming
GS[_6_] GS[_6_] is offline
external usenet poster
 
Posts: 1,182
Default Count the sum of multiply values in one cell, registered as part of a textcode, combine them per column and show the results in the next sheet

Hi Johan,

Am Fri, 31 May 2019 22:35:37 -0700 (PDT) schrieb JS SL:

In one of the first codes it was;
For i = LBound(varNames, 2) To UBound(varNames, 2)
z = i + 10
So, because I inserted also some columns in Sheet1 it was easy understanding
to change i+10 to i+26 because I change the startingpoint to column AA.

You have change this part of the code to
LColSh1 = .Cells(5, .Columns.Count).End(xlToLeft).Column
varNames = .Range(.Cells(5, firstSh1), .Cells(5, LColSh1))

So I thought I have to change it to
LColSh1 = .Cells(27, .Columns.Count).End(xlToLeft).Column
varNames = .Range(.Cells(5, firstSh1), .Cells(27, LColSh1))


when you insert columns the new ranges will be calculated automatically.
The only thing you must change in the code is the range for the codes
when this range has changed.
Make some test without changing the range for the codes. Insert or
delete columns in both sheets and you will see that the output is always
correct.


Regards
Claus B.


Claus,
Using Defined Names for various ranges eliminates the problems associated with
range addresses changing when inserting/deleting cols/rows, AND eliminates the
need for code updating as a result!

--
Garry

Free usenet access at http://www.eternal-september.org
Classic VB Users Regroup!
comp.lang.basic.visual.misc
microsoft.public.vb.general.discussion