0

I am new to VBA coding

I am trying to write a code to copy data from on sheet to another by searching and for that I am using recursion And the code looks something like this

Sub macro()
While s <> ""
Here comes copying each line and moving to the other page and searching for which row to post it on
After pasting 
Call macro and then there is 
end if
And wend
End sub

My issue here is when it comes to the call macro it starts from the first and then check for while condition and when the while condition is not met it should come out end the sub but it doesn't after end sub its again going back to end if.can someone help me with this

EDIT

Sub macro() 
dim issue as string 
dim i as integer 
  sheets(age).activate 
  while s <> "value" 
    activecell.offset(1,0) 
    Issue = active cell.value
    ActiveCell.Offset(, 1).Resize(1, 5).Copy 
    sheets(age1).activate 
    range(A1).select 
    for I =1 to 12 
      if active cell = issue activecell.offset(0,1) Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _ :=False, Transpose:=False    
        call macro 
      end if 
    Next i
  wend 
end sub
Community
  • 1
  • 1
Tej
  • 1
  • 3
  • 1
    Probably because that isn't actual code. Paste your real code so some one can try to help. – Rdster Nov 04 '16 at 18:14
  • Sub macro() dim issue as string dim i as integer sheets(age).activate while s <> "value" activecell.offset(1,0) ActiveCell.Offset(, 1).Resize(1, 5).Copy sheets(age1).activate range(A1).select for I =1 to 12 if active cell = issue activecell.offset(0,1) Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _ :=False, Transpose:=False call macro end if wend end sub. Where value is the end of the data – Tej Nov 04 '16 at 19:33
  • I added the code to the post, it shouldn't be in the comments, too hard to read. There is no way that code even compiles...you are missing "then" and "next I". Also the activecell thing could be part of your issue, try starting http://stackoverflow.com/questions/10714251/how-to-avoid-using-select-in-excel-vba-macros – Rdster Nov 04 '16 at 19:39
  • The code looks incomplete even after the edit – Techie Nov 04 '16 at 19:44
  • Hi ya sorry I don't have the code right now so typed it again ya it does have then for if statement and next I for "for" statement and after while part there is a code line issue = active cell.value – Tej Nov 04 '16 at 19:44
  • You never set the value of `s` which is used as the condition of your `WHILE` loop. If `s` never changes, then your While loop will just keep looping. That, and this code would never run as it's riddled with mistakes. Why don't you wait until you have your actual code to ask the question? – JNevill Nov 04 '16 at 20:39

0 Answers0