Peter Droz
Peter Droz

Reputation: 36

Automatically Updating Excel Tables using VBA

So I am trying to automate a process that when you click on a command button, then it will run this macro.

My objective is to first check to add the most recent date within the 1st range of values (in this case between C23 and C69) of the top-most empty cell. Once an empty cell is filled, I would want to kill the macro.

From there, in the next column I want to add a certain cell value (F21) into the most recent empty cell that is within D23 to D69. Same as above, once an empty cell is filled, I would want to kill the macro.

Once these values are given I can end the code. I would be able to write this in java, but I have no clue how to make this as a macro in excel vba so any help would be great! Thanks!

Here is my code currently (WHICH IS DEFINITELY VERY WRONG)

Sub ChartAdder()

Dim i As Range
For i = C23 To C69
    If IsEmpty(i) Then
        i = LastSavedATimeStamp()
    break

    Else
    keep going

Dim j As Range
For j = D23 To D69
    If IsEmpty(j) Then
        j = F21
    break

    Else
    keep going   

End Sub

Upvotes: 0

Views: 486

Answers (2)

pgSystemTester
pgSystemTester

Reputation: 9917

Here are some corrections to help you get something a little more geared towards what I think you area trying to do. If you write it in JavaScript, that would be probably helpful.

Sub ChartAdder()

    Dim i As Range

    For Each i In Range("C23:C69").Cells
        If IsEmpty(i) Then
            i = Date
        break

        Exit For

        End If

    Next i


    Dim j As Range
    For Each j In Range("D23:D69").Cells
        If IsEmpty(j) Then

            '
            j.Value = Range("F21").Value

        Exit For

        End If

    Next j

End Sub

Upvotes: 1

Peter Droz
Peter Droz

Reputation: 36

Thanks for the help! I was able to get a functional answer :D

Sub ChartAdder()

a = Date
b = F21
Dim i As Range

For Each i In Range("C23:C69").Cells
    If IsEmpty(i) Then
    i = a
    Exit For
    'Exit Sub will kill the whole macro
    'break

    End If

Next i


Dim j As Range
For Each j In Range("D23:D69").Cells
    If IsEmpty(j) Then
    .Value = Range("F21").Value
    Exit For
    'Exit Sub will kill the whole macro
    'break

    End If

Next j

End Sub

Upvotes: 0

Related Questions