简体   繁体   中英

Excel VBA Billing Userform input data questions

So I'm trying to code for an Excel VBA billing archive/tracker form for my work, and I am very new to excel vba. Any help would be much appreciated. Essentially, I want my userform to input billing date on the bottom table, then take the sum of the parts selected (A1-A19) and input the sum to the nearest, empty cell to the left of the input billing date. If it's the first billing cycle, then I just want to call the dollar amount in the Grand Total Engagement and put that value to the right of the input billing date. Attached are my snippits of the Excel sheet, and userform. Thanks so much community!

Excel Sheet

BillingArchiveUserform

'Creates "LastRow" variable
If Range("D47").Value = "" Then
LastRow = 47
Else
Main.Range("D46").Select
LastRow = Selection.End(xlDown).Row
End If

i = 47
Do While i <= LastRow
If BillingDate.Value = Range("D" & i).Value Then
If CmBBill.Value = "Yes" Then
'Range("D" & i).Offset( 'resume from here and figure it out, but I want to choose the nearest empty cell to the right of date
'Input project specific information (i.e. the sum of the parts that need to be billed)
Else
i = i + 1
End If
Loop

Cells(LastRow + 1, 4).Value = BillingDate.Value 'Inputs Billing Date

'2. Choose column of ProjectToBill based on value in textbox
Main.Range("E5").Select
LastCol = Selection.End(xlToRight).Column

1) You do not need a loop for this 2) You do not have any logic that checks if the userform checkboxes are set to true or false and then what to do if they are true/false. 3) Offset Property will be need to put information in lowe table in next available row. Offset can be sued to adjust left or right based obn your criteria, which will most likely be IF's 4) if first billing cycle you can direct the input to the first location in the lower area. 5) seeing in how your just dumping these into a spreadsheet, having to declare variables from textboxes in userforms is wont be needed. I do mention it however, because if you ever need to manipulate that information in VBA, it may need to be done so. And it looks like that simple math needs ot be done, so if you run into issues that may be the problem.

This should get you started in the right place

Private Sub commandbutton_click()

    If CheckBox1.Value = True Then Sheet1.Range("E4").Value = "Wherever you hid the predetermined value"
    If Sheet1.Range("d47").Value = vbNullString Then
        Sheet1.Range("d47").Value = BillingDateTextBox.Value
    Else
        Sheet1.Cells(Sheet1.Rows.Count, 1).End(xlUp).Offset(1, 0).Value = BillingDateTextBox.Value
        Sheet1.Cells(Sheet1.Rows.Count, 1).End(xlUp).Offset(0, 1).Value = "Wherever you hid the predetermined value"
    End If
End Sub

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM