Range problem in Loop

fefenouil

New Member
Joined
May 25, 2022
Messages
7
Office Version
  1. 2019
Platform
  1. Windows
Hi all,
Coming here again as I have a problem with my loop.
I am using this SerieLength in order to count the number of row so I can add different range of data one after the other.
I think that the counting is not working as when pasting the data on the new sheet and giving the new layout it applies only to a number of rows inferior to initial selected range.
Any idea on this would be welcomed with great appreciation.
Thanks

VBA Code:
Sub DatAnalysis()

'add new working sheet
Dim SheetName As String
SheetName = Application.InputBox(Prompt:="Sheet name", Type:=2)
Sheets.Add(Before:=Worksheets("raw")).Name = SheetName
Worksheets(SheetName).Activate
With Sheets(SheetName)

'do some stuff
   
'Set up for loop

    Dim SerieValue As Range
    Dim SerieName As String
    Dim Conc As Range
    Dim Condi As Boolean
    Dim CondiConc As Boolean
    Dim SerieLentgh As Integer
    Dim i As Integer
    Dim aver As Range
    Dim sd As Range
    Dim j As Integer
    j = 1
    i = 1
   
    Condi = False
   
        Do Until Condi = True
   
'selection of series values
            Worksheets("raw").Activate
            Set SerieValue = Application.InputBox(Prompt:="Pick Serie or empty cell if no more serie", Type:=8)
            If IsEmpty(SerieValue) Then Condi = True
            If Condi = True Then Exit Do
            If Not IsEmpty(SerieValue) Then Condi = False
            If Condi = False Then GoTo continue
continue:
            SerieLength = SerieValue.Rows.Count
            Worksheets(SheetName).Activate
            i = i + 1
            SerieValue.Copy Destination:=Cells(9, i)
   
'selection of concentration range
            Worksheets("raw").Activate
            Set Conc = Application.InputBox(Prompt:="select concentration range", Type:=8)
            Worksheets(SheetName).Activate
            Conc.Copy Destination:=Cells(8, i)
           
'name the serie
            SerieName = Application.InputBox(Prompt:="Please input serie name.", Type:=2)
            Cells(7, i).Value = SerieName
            Range(Cells(7, i), Cells(7, i + SerieLength)).Select
                Selection.Merge
                Selection.HorizontalAlignment = xlCenter
'transform data
            Range(Cells(13, i), Cells(15, i + SerieLength)).FormulaR1C1 = "=(((R[-4]C[0]-R6C2)/R6C1)*100)"
'average and stdev
            Set aver = Range(Cells(17, i), Cells(17, i + SerieLength))
                aver.FormulaR1C1 = "=AVERAGE(R[-4]C[0]:R[-2]C[0])"
            Set sd = Range(Cells(18, i), Cells(18, i + SerieLength))
                sd.FormulaR1C1 = "=STDEV(R[-5]C[0]:R[-3]C[0])"
    
'ad a graph
       
'Looping increment
        i = i + SerieLength
        j = j + 1
        Erase SerieLength
       
       
        Loop
       
End With
End Sub

Here is what source data look like and highlighted is the range selection on "raw" sheet
test code.xlsm
ABCDEFGHIJKLM
2
3CPP1CPP2bckgrnd +50waterbckgrnd +30water
451020505102050153149
55508562062589466740664053551465988759444166119
65654954699566685987967417520426101367668152127
73606342238447254341442802423654924638807bckgrnd +40waterbckgrnd +20water
8neg+10uL waterneg+20uL waterneg +50ul water136165
9473894292443375487773189739081320227005124151
10neg+30uL waterneg+40uL water1613722837140171
11335993525430960308225396220928bckgrnd +10water
12144163
1347389166
14429240,10,2123425
15433750,10,2123425
160,10,2123425
raw


And here is what I obtain on the new sheet. As you can see it seems like everything stopped after the 4th row whereas the selction was 6 rows in total

test code.xlsm
ABCDEFG
1negbckgrnd
247389136
342924124
443375140
5
644562,67133,3333
7k
85102050510
9550856206258946674066405355146
10565495469956668598796741752042
11360634223844725434144280242365
12
13123,3132138,9698131,9774150,9619
14126,5985122,447126,8655134,0711
1580,6272894,48417100,065197,12315
16
17average110,1797118,6337119,636127,3854
18stdev25,6457822,4866617,1405727,53503
fyuh
Cell Formulas
RangeFormula
B13:E15B13=(((B9-$B$6)/$A$6)*100)
B17:E17B17=AVERAGE(B13:B15)
B18:E18B18=STDEV(B13:B15)
 

Excel Facts

What is the shortcut key for Format Selection?
Ctrl+1 (the number one) will open the Format dialog for whatever is selected.
My bad I figured out that I was counting Rows instead of Columns this whole time
 
Upvote 0
Solution

Forum statistics

Threads
1,223,908
Messages
6,175,307
Members
452,633
Latest member
DougMo

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