Link to home
Create AccountLog in
Avatar of NYQuicksale
NYQuicksaleFlag 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

Avatar of StephenJR
StephenJR
Flag of United Kingdom of Great Britain and Northern Ireland image

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
Avatar of Saqib Husain
Saqib Husain
Flag of Pakistan image

Link to home
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
See answer
Avatar of 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
But since you are putting everything into A1 what is the point? Only the last value will remain.
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

Presumably you don't care to explain what you're doing then!
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/questions/27238987/Loop-Problem.html