Forum Discussion
hrh_dash
Jul 14, 2022Iron Contributor
Macro to display the data based on the info entered into the dialog boxes
I would like to create a macro with dialog boxes requesting users for the following information
- number of vendors
- names of vendors
- respective vendor amount
Therefore, if the users were to enter 5 number of vendors. it would populate 5 vendor names, with the amount and then there will be a summation of the total vendor amount at the last row.
Got stuck halfway trying to create the macro.
Dim FileName As String
Dim CountVendor As Integer
Dim Count As Integer
Dim sum1 As Long
Dim sum2 As Long
Dim ws As Worksheet
Set ws = Sheet1
FileName = InputBox("Please indicate this file name")
ws.Range("B1") = FileName
CountVendor = 0
CountVendor = InputBox("Please indicate number of vendors")
For Count = 1 To CountVendor
CountVendor = CountVendor + Count
ws.Range("A3") = InputBox("Name of Vendor " & Count)
ws.Range("B3") = InputBox("Please indicate Vendor " & Count & " Amount")
'For i = 2 To CountVendor
'ws.Range("A" & i).Value = CountVendor
'Next i
Next Count
sum1 = ws.Cells(ws.Rows.Count, "A").End(xlUp).row
sum2 = ws.Cells(ws.Rows.Count, "B").End(xlUp).row
ws.Range("A" & sum1 + 1).Value = "Total"
With ws.Range("B" & sum2 + 1)
.NumberFormat = "#,##0.00"
.Formula = "=SUM(B3:B & sum2)"
.Value = .Value
End With
So the table will look like this:
Appreciate the assistance provided.
This offers some minimal corrections
Sub userdata() Dim FileName As String Dim CountVendor As Integer Dim Count As Integer 'Dim sum1 As Long 'Dim sum2 As Long Dim ws As Worksheet Set ws = Sheet1 FileName = InputBox("Please indicate this file name") ws.Range("B1") = FileName CountVendor = 0 CountVendor = InputBox("Please indicate number of vendors") For Count = 1 To CountVendor ws.Range("A" & Count + 2) = InputBox("Name of Vendor " & Count) ws.Range("B" & Count + 2) = InputBox("Please indicate Vendor " & Count & " Amount") Next Count ws.Range("A" & CountVendor + 3).Value = "Total" With ws.Range("B" & CountVendor + 3) .NumberFormat = "#,##0.00" .Formula = "=SUM(B3:B" & CountVendor + 2 & ")" .Value = .Value End With End Sub
2 Replies
Sort By
- PeterBartholomew1Silver Contributor
This offers some minimal corrections
Sub userdata() Dim FileName As String Dim CountVendor As Integer Dim Count As Integer 'Dim sum1 As Long 'Dim sum2 As Long Dim ws As Worksheet Set ws = Sheet1 FileName = InputBox("Please indicate this file name") ws.Range("B1") = FileName CountVendor = 0 CountVendor = InputBox("Please indicate number of vendors") For Count = 1 To CountVendor ws.Range("A" & Count + 2) = InputBox("Name of Vendor " & Count) ws.Range("B" & Count + 2) = InputBox("Please indicate Vendor " & Count & " Amount") Next Count ws.Range("A" & CountVendor + 3).Value = "Total" With ws.Range("B" & CountVendor + 3) .NumberFormat = "#,##0.00" .Formula = "=SUM(B3:B" & CountVendor + 2 & ")" .Value = .Value End With End Sub
- hrh_dashIron Contributorthanks for the help! it works like a charm!