Link to home
Start Free TrialLog in
Avatar of NYQuicksale
NYQuicksaleFlag for United States of America

asked on

Loop Problem

this code doesn't work when there's just one symbol.

actually this code's purpose is to do the following:
i've sheet which contains too many ticker symbols and whenever one symbol is done, then cut and paste that symbol somewhere else and make that cell blank and goto next symbol, so whenevr i again run the loop, it would start from whatever next populated cell in that column. i hope u get the idea, but this below code doesn't work, when there's just one symbol there in column A

Sub loopC()
Dim cel As Range
Dim mySheet As Worksheet

Set mySheet = Sheets("info")

For Each cel In Sheets("symbols").Range("A" & Sheets("symbols").Range("A1").End(xlDown).Row & ":A" & Sheets("symbols").Range("A1").End(xlDown).End(xlDown).Row)
mySheet.Range("A1") = cel.Value
Next cel

End Sub

Open in new window

Avatar of NULL_ReferenceException
NULL_ReferenceException
Flag of United States of America image

I think you have a mixup where you're setting the value.  Try this
Sub loopC()
Dim cel As Range
Dim mySheet As Worksheet

Set mySheet = Sheets("info")

For Each cel In Sheets("symbols").Range("A" & Sheets("symbols").Range("A1").End(xlDown).Row & ":A" & Sheets("symbols").Range("A1").End(xlDown).End(xlDown).Row)
cel.Value = mySheet.Range("A1").Value
Next cel

End Sub

Open in new window

Note the difference between this:

mySheet.Range("A1") = cel.Value

And this:

cel.Value = mySheet.Range("A1").Value
ASKER CERTIFIED SOLUTION
Avatar of Saqib Husain
Saqib Husain
Flag of Pakistan image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of NYQuicksale

ASKER

it has entered into infinite loop
Which solution are you referring to?
both
Is your goal to select all the cells in column A that have text?
saqib your code is working now, why u didn't give it before? i'm just testing it every perspective, dun want to get into trouble again
Take your time. I am not in a hurry. You could have continued in the previous question and I would have been pleased to assist you.

...why u didn't give it before?

I never imagined you would want to cover "Only one" as well.

Saqib
that's by default, it can be from one to one million