Help with Loop Exit

fefenouil

New Member
Joined
May 25, 2022
Messages
7
Office Version
  1. 2019
Platform
  1. Windows
Hello,
I have recently started to code a macro to help me repetitive data analysis with very few knowledge in coding languages.
I have came up with this code, the idea is that I import my data on the sheet "raw" then I select the different series of values and name them in a new sheet. Since I have different set of data with variable length I came up with this loop that ask me what to copy/paste but I don't really know how to set up the Loop Exit for when I don't have anymore data to select. For the moment I have tinkered something with a conditional exit but I have to select an empty cell and then the rest of the loop still go on thus overwriting on the previous series.
I hope that my intent is understandable and if you have any tips to make the code more elegant it would be very much appreciated.
Thanks.

VBA Code:
Sub DataAnalysis()

'add new sheet

Sheets.Add(Before:=Worksheets("raw")).Name = "New"
Worksheets("New").Activate
With Sheets("New")

'negative value transfer
    Dim negval As Range
    Worksheets("raw").Activate
    Set negval = Application.InputBox(Prompt:="Pick the neg values", Type:=8)
    negval.Copy
    Worksheets("New").Activate
    Range("A2").PasteSpecial Paste:=xlPasteValues
    Range("A1").Value = "neg"
    Range("A6") = Application.WorksheetFunction.Average(Range("A2:A4"))
    
'peptides selection and transfer
    
    Dim SerieValue As Range
    Dim SerieName As String
    Dim Condi As Boolean
    Dim CondiConc As Boolean
    Dim SerieLentgh As Integer
    Dim i As Integer
    
  
  i = 1
    
    Do
    'selection of series values
    

        Worksheets("raw").Activate
        Set SerieValue = Application.InputBox(Prompt:="Pick Serie or empty cell if no more serie", Type:=8)
'At the moment my way out of the loop is by selecting a single empty cell but then it mess a bit up with the rest of the loop 

        If Not IsEmpty(SerieValue) Then Condi = False
        If IsEmpty(SerieValue) Then Condi = True
        SerieLength = SerieValue.Rows.Count
       
       
        Worksheets("New").Activate
        SerieName = Application.InputBox(Prompt:="Please input serie name.", Type:=2)
        SerieValue.Copy Destination:=Cells(3, i).Offset(0, 1)
        Cells(1, i).Offset(0, 1).Value = SerieName
        Range(Cells(1, i + 1), Cells(1, i + SerieLength)).Merge
     
        'Range(Cells(1, i)).HorizontalAlignment = xlCenter
        
        
 
    i = i + SerieLength
    Loop Until Condi = True

 Dim SheetName As String
     SheetName = InputBox("Please input sheet name.")
     ActiveSheet.Name = SheetName

End With 
End Sub
 

Excel Facts

Excel Can Read to You
Customize Quick Access Toolbar. From All Commands, add Speak Cells or Speak Cells on Enter to QAT. Select cells. Press Speak Cells.
(y) You are very welcome
And thank you for the feedback
Be happy and safe
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,181
Members
453,022
Latest member
Mohamed Magdi Tawfiq Emam

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