Search : in
By :

Pretty Basic Excel Macro Help

Last answer on Dec 18, 2008 1:09:44 pm GMT The Reinman, on Jul 15, 2008 6:05:33 pm BST 
 Report this message to moderators

Hello,

I am writing a macro (which will be used to create a VB6 program) in Excel 2003.

The spreadsheet Update_Log is a database with 9 user input columns and 7 columns which are calculated by formulas based on user input. I need to create a macro that finds the last record in column A, moves one more row down. and enters the data. The first column is a primary key which starts with the value 1 (@ A9) and increases sequentially (2, 3, 4, etc.). A second sheet, Sheet 2, has text boxes to accept the user input.

If anyone can provide the code for creating the new row, automatically add the Log Key at the next value, and show how to add the input from a txtbox (called OperatortTXT) in the same row to column B, it would be greatly appreciated.

If any clarification is needed, please reply or email.

Thanks,

Reinman

Configuration: Windows XP
Internet Explorer 6.0

Best answers for « Pretty Basic Excel Macro Help » in :
Basic Excel Formulas ShowBasic Excel Formulas Below are some basic formulas for Microsoft excel: Basic formula : ADDITION cell A1 to A10 = sum (A1: A10) AVERAGE cell A1 to A10 = average (A1: A10) MAXIMUM cell A1 to A10 = max (A1: A10) MINIMUM...
Basic Excel Formulas 2 ShowBasic Excel Formulas 2 We saw the SI function Function and is also interesting. Combined with SI, this gives: = IF (AND (condition1; condition2 ;....... conditionZ) true false) displays on the various conditions to be verified (eg...
Inserting an animated gif in Excel ShowInserting an animated gif in Excel To insert an animated gif image in an Excel spreadsheet, you must insert the image into a control. To insert the control, go to the View menu/Toolbars/Control Toolbox Activate the first button Design...

1

 Ivan-hoe, on Jul 16, 2008 8:18:08 am BST
  • +3

Hello,
I guess you click on a button to validate the data put in the textboxes.
Your VBA macro could look like this :

Private Sub CommandButton1_Click()
    Dim LastLine As Integer, NewLine As Integer
    
    With Sheets("Update_log")
        LastLine = .Cells(Rows.Count, "A").End(xlUp).Row
        NewLine = LastLine + 1
        
        If Not IsNumeric(.Cells(LastLine, "A").Value) Then
            .Cells(NewLine, "A").Value = 1
        Else
            .Cells(NewLine, "A").Value = .Cells(LastLine, "A").Value + 1
        End If
        
        .Cells(NewLine, "B").Value = OperatorTXT.Value: OperatorTXT.Value = Empty
        .Cells(NewLine, "C").Value = OperatorTXT2.Value: OperatorTXT2.Value = Empty
    End With
End Sub

Ivan

Reply to Ivan-hoe