dlongnecker
MIS
As I attempt to familiarize myself with Excel’s VBA functionalities, I’ve been working on a “pseudo” spreadsheet before I apply it to a working case (out of one of our Excel trainer's books) in my organization.
I am attempting to create an automated sheet that will allow us to take information from a “Data Entry” sheet and build a report on the fly. I have three cells that contain formulas. The data is laid out:
As it is, I’ve coded and can pull the name of the salesperson over to the “Report” sheet; however, I’m having difficulty parsing the rows’ data.
For example, in pseudo-code, I would envision:
That would, in hope, spit out those numbers in the correct column (next to the person’s name) on the third sheet.
I’ve stumped our trainer~ Any suggestion or alternatives would be great. I’m sure I’m taking the “long road” in doing some of this. I’ve posted the existing code below and it has most of the necessary comments in it (so I don’t forget what I’m doing (^_^;
).
Thanks!
-David
David R. Longnecker
CCNA, MCSA, Network+, A+
Management Information Services
Wichita Public Schools, USD 259
I am attempting to create an automated sheet that will allow us to take information from a “Data Entry” sheet and build a report on the fly. I have three cells that contain formulas. The data is laid out:
Code:
Column A Column B Column C Column D
Name Sales #1 Sales #2 Sales #3
As it is, I’ve coded and can pull the name of the salesperson over to the “Report” sheet; however, I’m having difficulty parsing the rows’ data.
For example, in pseudo-code, I would envision:
Code:
For each row 5:END
Sheet(3).Range(B) = ColumnB Value * Variable1
Sheet(3).Range(C) = ColumnC Value * Variable2
Etc.
Next
That would, in hope, spit out those numbers in the correct column (next to the person’s name) on the third sheet.
I’ve stumped our trainer~ Any suggestion or alternatives would be great. I’m sure I’m taking the “long road” in doing some of this. I’ve posted the existing code below and it has most of the necessary comments in it (so I don’t forget what I’m doing (^_^;
Thanks!
-David
Code:
Sub GenerateSales()
' Ask user: are you sure you want to do this?
YesNo = MsgBox("This macro generate a current sales report. This will remove the previous report. Do you want to continue?", vbYesNo + vbCritical, "Caution")
Select Case YesNo
Case vbYes
' Does a report already exist?
Report = False
For Each s In Worksheets
If s.Name = "Report" Then
Report = True
Exit For
End If
Next s
If Report = True Then
' Yeah, we've got a report. Trash it.
Application.DisplayAlerts = False
Sheets("Report").Delete
Application.DisplayAlerts = True
End If
' Create a new report, set column widths, and name.
Sheets.Add After:=Sheets(2)
ActiveSheet.Name = "Report"
Range("A1").ColumnWidth = 16
Range("B1").ColumnWidth = 20
' Pull all salespersons names from Data Entry sheet to Report sheet.
Sheets(2).Select
Sheets(2).Range("B15").Select
Call SelectColumn
Selection.Copy
Sheets(3).Select
Range("B6").Select
ActiveSheet.Paste
Sheets(2).Select
' Begin manulipulating data from Data Entry sheet.
' Pull variables from Data Entry sheet, place into strings.
Sheets(2).Select
varStandard = Range("C6")
varPriority = Range("C7")
varNewBonus = Range("C9")
' Add the current date/time to the report.
Sheets(3).Range("B2") = Now
Sheets(3).Range("A2") = "Report Date:"
Sheets(3).Range("A1") = "Pewter's Pottery"
' Completed; go to sheet Report.
Sheets(3).Select
Case vbNo
End
End Select
End Sub
Sub SelectColumn()
Dim UpBound As Range
Dim LowBound As Range
If ActiveCell.Row > 1 Then
If IsEmpty(ActiveCell.Offset(-1, 0)) Then
Set UpBound = ActiveCell
Else
Set UpBound = ActiveCell.End(xlUp)
End If
Else
Set UpBound = ActiveCell
End If
If ActiveCell.Row < Rows.Count Then
If IsEmpty(ActiveCell.Offset(1, 0)) Then
Set LowBound = ActiveCell
Else
Set LowBound = ActiveCell.End(xlDown)
End If
Else
Set LowBound = ActiveCell
End If
Range(UpBound, LowBound).Select
Set UpBound = Nothing
Set LowBound = Nothing
End Sub
David R. Longnecker
CCNA, MCSA, Network+, A+
Management Information Services
Wichita Public Schools, USD 259