|
-
May 19th, 2013, 03:26 PM
#1
Thread Starter
Junior Member
Initiating a do until loop
Hello!
I have a large set of data that I want to be extracted into certain phases. And I am trying to write a code to do so. For example the freezing cycle begins when the value in column F hits 1 and G is 18 goes until it F is 10 and G is -35 I am familiar with the do until loop which I have now and that will extract up until F is 10 and G is -15 However, is there a way to set an initial condition (F=1 and G=18)? The code below has it extracting and putting into new sheet. Thank you for your help!!
Dim mycount As Integer
mycount = 0
Dim myrow As Integer
myrow = 1
Dim oldrow As Integer
Dim startnext As Integer
Do
mycount = mycount + 1
oldrow = myrow + 1
startnext = oldrow
Sheets("Data").Select ''must be name of sheet with data
Do Until Cells(myrow, 6).Value = "10" And Cells(myrow, 7).Value = "-35"
myrow = myrow + 1
Loop
Sheets.Add
ActiveSheet.Name = "FreezeData"
Sheets("Data").Select
rows(oldrow & ":" & myrow).Select
Selection.Copy
Sheets("FreezeData").Select
Range("A1").Select
ActiveSheet.Paste
Loop Until Sheets("Data").Cells(1, myrow + 1) = ""
-
May 19th, 2013, 03:57 PM
#2
Re: Initiating a do until loop
However, is there a way to set an initial condition (F=1 and G=18)?
not while you are reading the cells, you would have to use variables and assign the cell value to the variables within the loop, that way you could assign specific values to the variables prior to commencing the loop, maybe better to loop until, rather than do until, as you do with your other do loop
i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next
dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part
come back and mark your original post as resolved if your problem is fixed
pete
-
May 19th, 2013, 08:06 PM
#3
Thread Starter
Junior Member
Re: Initiating a do until loop
 Originally Posted by westconn1
not while you are reading the cells, you would have to use variables and assign the cell value to the variables within the loop, that way you could assign specific values to the variables prior to commencing the loop, maybe better to loop until, rather than do until, as you do with your other do loop
I don't think I understand what you mean? How would that initiate the loop? Could you give me an example?
Thank you!
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|