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

VB ScriptMicrosoft Excel

Avatar of undefined
Last Comment
NYQuicksale
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

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
Avatar of NYQuicksale
NYQuicksale
Flag of United States of America image

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
Avatar of StephenJR
StephenJR
Flag of United Kingdom of Great Britain and Northern Ireland image

But since you are putting everything into A1 what is the point? Only the last value will remain.
Avatar of sungenwang
sungenwang
Flag of United States of America image

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

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

Presumably you don't care to explain what you're doing then!
Avatar of NYQuicksale
NYQuicksale
Flag of United States of America image

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/questions/27238987/Loop-Problem.html
Microsoft Excel
Microsoft Excel

Microsoft Excel topics include formulas, formatting, VBA macros and user-defined functions, and everything else related to the spreadsheet user interface, including error messages.

144K
Questions
--
Followers
--
Top Experts
Get a personalized solution from industry experts
Ask the experts
Read over 600 more reviews

TRUSTED BY

IBM logoIntel logoMicrosoft logoUbisoft logoSAP logo
Qualcomm logoCitrix Systems logoWorkday logoErnst & Young logo
High performer badgeUsers love us badge
LinkedIn logoFacebook logoX logoInstagram logoTikTok logoYouTube logo