+ Reply to Thread
Results 1 to 6 of 6

Trying to get vba loop to execute cell by cell

  1. #1
    Registered User
    Join Date
    09-07-2017
    Location
    New York
    MS-Off Ver
    2016
    Posts
    7

    Trying to get vba loop to execute cell by cell

    Hi, first time using this forum. So apologies if I don't know all the rules.

    I'm working on an excel spreadsheet. And would like to implement a unique ID column (like access has). I found some via code and compiled them to suit my need. But I hit a roadblock.

    Here's what I'd like to do. I have lots of rows with contact info, and I want to add a ID column, now till now I just typed in 1001 on the first row. And filled it down. The only thing is that I constantly copy in filled in rows from another sheet. And since my rows aren't sorted consecutively... I can't just fill in an ID for the newly pasted rows, since I'm not sure if the last highest number used...

    So I have this code (below) that runs through my selection and fills in the blank cells with the highest number found in the ID column + 1... the only thing is that if it fills in all blanks with that same newly calculated value. Instead of each blank row with a consecutive number. I guess all I'm trying figure out is how to modify this code to recalculate and rerun the function 1 cell at a time (I guess from the top down).
    If anyone can help me out I'd greatly appreciate it. perhaps I've been doing this wrong all along.


    Here's the code that I have now:
    (See attached pic for results)
    HTML Code: 

    Sub FillEmptyBlankCellWithValue()
    Dim cell As Range
    Dim InputValue As String
    On Error Resume Next
    InputValue = Application.WorksheetFunction.Max(Columns("A")) + 1
    For Each cell In Selection
    If IsEmpty(cell) Then
    cell.Value = InputValue
    End If
    Next
    End Sub
    Function Max_Each_Column(Data_Range As Range) As Integer
    Dim TempArray() As Double, i As Long
    If Data_Range Is Nothing Then Exit Function
    With Data_Range
    ReDim TempArray(1 To .Columns.Count)
    For i = 1 To .Columns.Count
    TempArray(i) = Application.Max(.Columns(i))
    Next
    End With
    Max_Each_Column = TempArray
    End Function

  2. #2
    Forum Expert
    Join Date
    04-23-2009
    Location
    Matrouh, Egypt
    MS-Off Ver
    Excel 2013
    Posts
    6,882

    Re: Trying to get vba loop to execute cell by cell

    Hello
    Try this code
    Please Login or Register  to view this content.
    < ----- Please click the little star * next to add reputation if my post helps you
    Visit Forum : From Here

  3. #3
    Registered User
    Join Date
    09-07-2017
    Location
    New York
    MS-Off Ver
    2016
    Posts
    7

    Re: Trying to get vba loop to execute cell by cell

    See link for pic

    https://photos.app.goo.gl/CTkOxscunWHGS0et1

  4. #4
    Registered User
    Join Date
    09-07-2017
    Location
    New York
    MS-Off Ver
    2016
    Posts
    7

    Re: Trying to get vba loop to execute cell by cell

    Oh wow, that was quick.. thanks so much!! gimme a sec, I'll try it out.

  5. #5
    Registered User
    Join Date
    09-07-2017
    Location
    New York
    MS-Off Ver
    2016
    Posts
    7

    Re: Trying to get vba loop to execute cell by cell

    Yes yes!!! It works thanks so much your a savior. May god bless you!

  6. #6
    Forum Expert
    Join Date
    04-23-2009
    Location
    Matrouh, Egypt
    MS-Off Ver
    Excel 2013
    Posts
    6,882

    Re: Trying to get vba loop to execute cell by cell

    You're welcome. Glad I can offer some help

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. [SOLVED] Copy Cell From One Cell and Paste to next blank cell, Loop until last row/column
    By Beginner Level in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 05-01-2020, 02:38 AM
  2. [SOLVED] If CELL is blank the execute formula1, IF Cell is not blank execute formula 2
    By grahamlees in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 07-13-2017, 06:47 AM
  3. [SOLVED] Loop copy cell of range to 1 cell, and so on till cell empty
    By countryfan_nt in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 02-16-2017, 02:33 AM
  4. IF cell=error execute sub 1 if value execute sub 2... possible?
    By CDNcameron in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 07-31-2013, 05:28 PM
  5. Loop that waits for a subroutine to execute
    By Aristizabal95 in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 07-02-2013, 11:38 PM
  6. lines in loop don't execute when program is run
    By akaron in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 08-23-2012, 11:02 AM
  7. [SOLVED] ADO command.execute with a loop - only runs once
    By George King in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 02-09-2006, 02:35 PM

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1