0% found this document useful (0 votes)
2 views2 pages

CodeForClass16Demo

The document contains VBA code for an Excel application with multiple subroutines that handle user input and perform calculations. It allows users to input values, calculate maximum, minimum, and sums based on specified ranges in columns A and B. The code includes prompts for user-defined ranges and outputs results in designated cells.

Uploaded by

Ronald
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views2 pages

CodeForClass16Demo

The document contains VBA code for an Excel application with multiple subroutines that handle user input and perform calculations. It allows users to input values, calculate maximum, minimum, and sums based on specified ranges in columns A and B. The code includes prompts for user-defined ranges and outputs results in designated cells.

Uploaded by

Ronald
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

Private Sub cmdInput_Click()

range("d7") = InputBox("Enter a value")


inputval = InputBox("Enter a value")
range("d8") = range("d7") * inputval
End Sub
Private Sub cmdMax_Click()
range("D1") = Application.Max(range("a1:a10"))
range("D2") = Application.SumIfs(range("a1:a10"),
range("a1:a10"), ">5")
' now use lastrow
lastrow = range("b65000").End(xlUp).Row
range("D3") = Application.Min(range("b1:b" & lastrow))
End Sub

Option Explicit
Dim lastrow, lastcell
Dim firstrow

Private Sub cmdSum1_Click()


' put sum of values from a1 to end in b1
lastrow = range("a65000").End(xlUp).Row
range("b1") = Application.Sum(range("a1:a" & lastrow))
End Sub

Private Sub cmdSum2_Click()


'Prompt for the last row to use
lastrow = InputBox("Enter last row")
'Use the lastrow input as the last row to sum up in column A
range("b2") = Application.Sum(range("a1:a" & lastrow))
End Sub
Private Sub cmdSum3_Click()
'prompt for first and last rows
firstrow = InputBox("enter first row")
lastrow = InputBox("enter last row")
'use the first and last row to sum up a range in column A
range("b3") = Application.Sum(range("a" & firstrow & ":a" &
lastrow))
End Sub

You might also like