Avatar of NYQuicksale
NYQuicksale
Flag for United States of America asked on

Loop Starting from blank cells

I want the below loop to get started from the whatever first cell is populated within the symbols sheet. e.g if cell A1,A2,A3 are blank then automatically start from A4.

Sub loopA()
Dim cel As Range
Dim sh As Worksheet

Set sh = Sheets("info")

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

Open in new window

VB ScriptMicrosoft Excel

Avatar of undefined
Last Comment
NYQuicksale

8/22/2022 - Mon
StephenJR

What is your code doing - it is just overwriting A1 each time? You don't need a loop at all do you?
ASKER CERTIFIED SOLUTION
Saqib Husain

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
NYQuicksale

ASKER
i need a loop, this is the same, that u just amended, earlier it was taking in blank cells as well, while now i want it to start from whatever populated cell is in the Column A, i mean not to start from some fixed cell i-e A1 or A2, i want it to check from which cell it is starting the non-blank cells, and then get into the loop from that cell onwards
StephenJR

But since you are putting everything into A1 what is the point? Only the last value will remain.
Experts Exchange is like having an extremely knowledgeable team sitting and waiting for your call. Couldn't do my job half as well as I do without it!
James Murphy
sungenwang

Try this... nonBlankRow will have the row number of the first non-blank row.
sew

Sub LoopA()
    Dim cel As Range
    Dim sh As Worksheet
    
    Set sh = Sheets("info")
    
    Set sh2 = Sheets("symbols")
    sh2.Range("A1").Select
    Selection.End(xlDown).Select
    
    Dim nonBlankRow As Integer
    nonBlankRow = ActiveCell.Row

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

Open in new window

StephenJR

Presumably you don't care to explain what you're doing then!
NYQuicksale

ASKER
stephen sorry, i dont have time actually to explain everything what i do, and in that hurry, i accepted solution which is not working for one symbol, so i'm posting a new question, that would be for u, i'm gonna explain everything there.
https://www.experts-exchange.com/Programming/Languages/Visual_Basic/VB_Script/Q_27238987.html
Get an unlimited membership to EE for less than $4 a week.
Unlimited question asking, solutions, articles and more.