Consulting

Results 1 to 16 of 16

Thread: Solved: BACK FILLING DATA

  1. #1

    Solved: BACK FILLING DATA

    Hello Guys,

    I need a solution to my problem. Please Find the Attached Excel File for my problem.

    I want to fill the data to Upward. I have mentioned in the Excel File.

    Actually I have created a Macro, but it takes much time, here is my Macro code.

    [VBA]
    Sub fillup()
    Dim i, j As Integer
    Dim lr As Variant
    lr = ActiveSheet.UsedRange.Rows.Count
    que = InputBox("Enter the Column")
    On Error GoTo ERROR
    Application.ScreenUpdating = False
    For i = 1 To lr
    j = i
    While Range(que & j).Value = ""
    j = j + 1
    Range(que & i).Value = Range(que & j).Value
    Wend
    Next
    ERROR:
    Exit Sub
    End Sub

    [/VBA]
    What's wrong with my Code?
    Thanks in Advance,
    krrish
    Happiness keeps u sweet, trials keep u strong, sorrow keeps u human, failure keeps u humble, success keeps u glowing, but only God keeps u going

  2. #2
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    [vba]

    Public Sub ProcessData()
    Dim Lastrow As Long
    Dim i As Long

    Application.ScreenUpdating = False

    With ActiveSheet

    Lastrow = .Cells(.Rows.Count, "A").End(xlUp).Row
    For i = Lastrow To 2 Step -1

    If Cells(i - 1, "A").Value2 = "" Then

    Cells(i - 1, "A").Value2 = Cells(i, "A").Value2
    End If
    Next i
    End With

    Application.ScreenUpdating = True
    End Sub
    [/vba]
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  3. #3
    Quote Originally Posted by xld
    [vba]

    Public Sub ProcessData()
    Dim Lastrow As Long
    Dim i As Long

    Application.ScreenUpdating = False

    With ActiveSheet

    Lastrow = .Cells(.Rows.Count, "A").End(xlUp).Row
    For i = Lastrow To 2 Step -1

    If Cells(i - 1, "A").Value2 = "" Then

    Cells(i - 1, "A").Value2 = Cells(i, "A").Value2
    End If
    Next i
    End With

    Application.ScreenUpdating = True
    End Sub
    [/vba]
    As always You are Great, Thank you So Much Man.

    Could you please explain, why my code takes very long time??

    Thanks Again,
    Happiness keeps u sweet, trials keep u strong, sorrow keeps u human, failure keeps u humble, success keeps u glowing, but only God keeps u going

  4. #4
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    How much data do you have? Do you have a lot of formulae?
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  5. #5
    Quote Originally Posted by xld
    How much data do you have? Do you have a lot of formulae?
    Hi Xld,

    The data is matter of 200 - 500 rows, and i don't use any formulae.

    Is my code is good?
    Happiness keeps u sweet, trials keep u strong, sorrow keeps u human, failure keeps u humble, success keeps u glowing, but only God keeps u going

  6. #6
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    I am sorry, I am not sure. It should be fast. Post the workbook.
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  7. #7
    Quote Originally Posted by xld
    I am sorry, I am not sure. It should be fast. Post the workbook.
    Ya sure,

    Please Find my Excel Sample WorkBook.

    I checked mine and Your's, Your's is like Rocket fast and Mine is like drowsy bug
    Happiness keeps u sweet, trials keep u strong, sorrow keeps u human, failure keeps u humble, success keeps u glowing, but only God keeps u going

  8. #8
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    I thought you were saying mine was slow. If it is fast, what is the problem?
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  9. #9
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    BTW, mine can be even faster

    [vba]

    Public Sub ProcessData()
    Dim Lastrow As Long
    Dim Startrow As Long
    Dim i As Long

    Application.ScreenUpdating = False

    With ActiveSheet

    Lastrow = .Cells(.Rows.Count, "A").End(xlUp).Row
    For i = Lastrow To 2 Step -1

    Startrow = i
    Do While .Cells(Startrow - 1, "A").Value2 = "" And Startrow >= 2

    Startrow = Startrow - 1
    Loop
    If Startrow < i Then .Cells(Startrow, "A").Resize(i - Startrow).Value = .Cells(i, "A").Value
    Next i
    End With

    Application.ScreenUpdating = True
    End Sub
    [/vba]
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  10. #10
    Quote Originally Posted by xld
    I thought you were saying mine was slow. If it is fast, what is the problem?
    Sorry Xld,

    Mis Understand here,

    I am saying, Mine is slow.

    Yours is like rocket fast.
    Happiness keeps u sweet, trials keep u strong, sorrow keeps u human, failure keeps u humble, success keeps u glowing, but only God keeps u going

  11. #11
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    Yeah, yours is slow because you have a loop within a loop. So you process all rows, and then within each iteration of the loop, you process all of the blank rows again. And to make it worse, you rewrite back all but one of the blanks in each iteration of the outer loop.
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  12. #12
    Quote Originally Posted by xld
    Yeah, yours is slow because you have a loop within a loop. So you process all rows, and then within each iteration of the loop, you process all of the blank rows again. And to make it worse, you rewrite back all but one of the blanks in each iteration of the outer loop.
    Thanks you very much xld,

    That's what I need to know, , Could you please modify my code, that will work fast.

    Sorry to Irritating you, I am just a beginner to learn vba.

    I have seen you around here, You are like just amazing. I don't mind if you believe it or not, I worship you man.
    Happiness keeps u sweet, trials keep u strong, sorrow keeps u human, failure keeps u humble, success keeps u glowing, but only God keeps u going

  13. #13
    @xld

    thanks for your help Man. I will Mark this thread As Solved.

    Once Again Thank you very much.

    You are rocking.
    Happiness keeps u sweet, trials keep u strong, sorrow keeps u human, failure keeps u humble, success keeps u glowing, but only God keeps u going

  14. #14
    [quote=xld]Lastrow To 2 Step -1quote]

    What is the 2 step mean?

    Please don't get angry, i am newbie in vba
    Happiness keeps u sweet, trials keep u strong, sorrow keeps u human, failure keeps u humble, success keeps u glowing, but only God keeps u going

  15. #15
    Knowledge Base Approver VBAX Guru GTO's Avatar
    Joined
    Sep 2008
    Posts
    3,368
    Location
    Hi there,

    The statement reads more like 'For i equals Lastrow to 2' The Step -1 part tells the loop that we are going from an upper value to a lower value, instead of the 'normal' from a lower value to a higher value.

    Thus, if the last row with data was row 20, 'i' would equal 20 the first time thru the loop, 19 the second time and so on.

    In vba help, look up 'For...each...next'

  16. #16
    Thanks GTO,
    Really helpful Explanation. Thank you so much .
    Happiness keeps u sweet, trials keep u strong, sorrow keeps u human, failure keeps u humble, success keeps u glowing, but only God keeps u going

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •