sorry for the delay, greg, i don't have internet access on the
weekend........
yes, here is some working coding........
like i said, this is somewhat backwards, but it should give you some
ideas. this is a monthly workbook that when you press the "update"
button it calls up a userform in which my boss can choose which
program's info she wants to export, then automatically exports the
info to a master workbook (RPCbook1.xls). the macro is stored in the
monthly book, called invoices.xls.
future improvements: the "if month" section could probably be changed
to a case statement, but i haven't worked on that yet. also, the
whole "if chkbox*** = true then" could be made into a case statement
with a variable for the program name. complete the "add new" feature.
hope this helps!
module names are listed.
in the interim i will work on something small that does what you
specifically wanted.
susan
===========================
Document: <date>Invoices.xls
Module: GlobalDeclarations
Option Explicit
Public wbMyInvoices As Workbook
Public wsMyIndirectSheet As Worksheet
Public wbMyRPC As Workbook
Public wsMyRPCSheet As Worksheet
Public Month, m, PrevMonth As Integer
Public dt As Date
Public Jan, Feb, Mar As Worksheet
Public Apr, May, Jun As Worksheet
Public Jul, Aug, Sep As Worksheet
Public Oct, Nov, Dec As Worksheet
Public Sum As Worksheet
Public r As Range
Public StartRow, EndRow As Long
Public rFound, myCosts, StartPoint As Range
Public InvoicePercent, RPCPercent, rReturn As Range
Public chkTotal, chkAHC06, chkDANC05 As Control
Public chkHPG05, chkHPG06, chkLCHOME05 As Control
Public chkCHDO06, chkCro, chkLCHBYR05 As Control
Public chkMicro, chkAccess, chkRentals, chkRPC As Control
Public chkKeepOpen As Boolean
Public chkAddNew, chkNew, refNewName As Control
Public myNewName, myProgram As String
Public cmdExport As Control
Public Sub MonthNumber()
'Set Current Date.
dt = DateTime.Date
'Break up the date.
m = DateTime.Month(dt)
If m <= 1 Then
PrevMonth = (m + 11)
End If
If m >= 2 Then
PrevMonth = (m - 1)
End If
End Sub
Public Sub Select_Sheet()
Set Jan = Workbooks("RPC Book1.xls").Worksheets("Sheet1")
Set Feb = Workbooks("RPC Book1.xls").Worksheets("Sheet2")
Set Mar = Workbooks("RPC Book1.xls").Worksheets("Sheet3")
Set Apr = Workbooks("RPC Book1.xls").Worksheets("Sheet4")
Set May = Workbooks("RPC Book1.xls").Worksheets("Sheet5")
Set Jun = Workbooks("RPC Book1.xls").Worksheets("Sheet6")
Set Jul = Workbooks("RPC Book1.xls").Worksheets("Sheet7")
Set Aug = Workbooks("RPC Book1.xls").Worksheets("Sheet8")
Set Sep = Workbooks("RPC Book1.xls").Worksheets("Sheet9")
Set Oct = Workbooks("RPC Book1.xls").Worksheets("Sheet10")
Set Nov = Workbooks("RPC Book1.xls").Worksheets("Sheet11")
Set Dec = Workbooks("RPC Book1.xls").Worksheets("Sheet12")
Set Sum = Workbooks("RPC Book1.xls").Worksheets("Summary")
If PrevMonth = 1 Then
Jan.Select
End If
If PrevMonth = 2 Then
Feb.Select
End If
If PrevMonth = 3 Then
Mar.Select
End If
If PrevMonth = 4 Then
Apr.Select
End If
If PrevMonth = 5 Then
May.Select
End If
If PrevMonth = 6 Then
Jun.Select
End If
If PrevMonth = 7 Then
Jul.Select
End If
If PrevMonth = 8 Then
Aug.Select
End If
If PrevMonth = 9 Then
Sep.Select
End If
If PrevMonth = 10 Then
Oct.Select
End If
If PrevMonth = 11 Then
Nov.Select
End If
If PrevMonth = 12 Then
Dec.Select
End If
Set rReturn = ActiveSheet.Range("a2")
End Sub
Module: OpenForm
Option Explicit
Sub MyExports_click()
Load UserForm1
UserForm1.Show
End Sub
Module: ExportValues
Option Explicit
Public Sub ActualCopy()
Set r = wsMyIndirectSheet.Columns("G")
'find the program name in wsMyIndirectSheet
Set rFound = r.Find(What:=myProgram, _
LookIn:=xlValues, _
LookAt:=xlWhole, _
MatchCase:=False)
If rFound Is Nothing Then
MsgBox "Sorry, " & myProgram & " was not found" _
& vbCrLf & _
"in the Invoice sheet."
Exit Sub
End If
StartRow = rFound.End(xlToLeft) _
.End(xlToLeft).End(xlDown).End(xlDown).Row
EndRow = rFound.End(xlToLeft).End(xlToLeft) _
.End(xlDown).End(xlDown) _
.End(xlDown).Offset(-1, 0).Row
'set the 2 ranges you will need to copy
Set myCosts = wsMyIndirectSheet.Range("h" & StartRow & ":h" & EndRow)
Set InvoicePercent = rFound.Offset(5, -1)
myCosts.Copy
'find the appropriate column in wsMyRPCSheet
'& then paste
Set StartPoint = wsMyRPCSheet.Range("a4")
Set r = StartPoint.EntireRow
Set rFound = r.Find(What:=myProgram, _
LookIn:=xlValues, _
LookAt:=xlWhole, _
MatchCase:=False)
If rFound Is Nothing Then
MsgBox "Sorry, " & myProgram & " was not found" _
& vbCrLf & _
"in the RPC sheet."
Exit Sub
End If
Set StartPoint = rFound.Offset(1, 0) '.Address
StartPoint.PasteSpecial (xlPasteValues)
'then offset 5 columns (to column F) for
InvoicePercent.Copy
Set RPCPercent = rFound.Offset(20, 0)
RPCPercent.PasteSpecial (xlPasteValues)
End Sub
Public Sub Overhead()
'Public wsMyIndirectSheet As Worksheet
'Public wsMyRPCSheet As Worksheet
wsMyRPCSheet.Range("n25") = wsMyIndirectSheet.Range("q1")
wsMyRPCSheet.Range("n26") = wsMyIndirectSheet.Range("q2")
wsMyRPCSheet.Range("n27") = wsMyIndirectSheet.Range("q4")
wsMyRPCSheet.Range("n28") = wsMyIndirectSheet.Range("q3")
End Sub
Module: Userform1 code
Option Explicit
'
'this workbook contains a
'set of macros designed and developed
'by Susan
'for xxxxxx
'completed 12/22/06 except for
'add new boxes; maybe do later
'
'revised 12/29/06 to add progress
'bar coding
'revised 2/13/07 to add HPG 2006 & remove
'Croghan CDBG
'
Sub UserForm_Initialize()
'check all the boxes automatically except for
'the keepopen and addnew checkboxes
Dim oControl As Control
For Each oControl In Me.Controls
If TypeOf oControl Is msforms.CheckBox Then
oControl.Value = True
End If
Next oControl
With Me
..chkAddNew.Value = False
..chkKeepOpen.Value = False
..cmdExport.SetFocus
End With
End Sub
Sub cmdExport_click()
Me.Hide
'check if the addnew checkbox is true
'if it is, then call addanother (in future)
If Me.chkAddNew.Value = True Then
MsgBox "The ""Add a New Program"" feature is currently not available."
_
& vbCrLf & _
vbCrLf & _
"Please e-mail Susan and have her add the new program manually." _
& vbCrLf & _
vbCrLf & _
" Signed, your friend, the Computer.", vbOKOnly,
"Whoops!"
End If
Application.ScreenUpdating = False
call Main
Unload Me
Application.ScreenUpdating = True
MsgBox "All values have been exported." _
& vbCrLf & _
vbCrLf & _
"Have a nice day!", vbOKOnly, "We're finished now..."
End Sub
Module: MainProgram
Option Explicit
Sub Main()
ProgressForm.chkWkshtCode.Value = True
Set wbMyInvoices = ThisWorkbook
Set wsMyIndirectSheet = ActiveSheet
Workbooks.Open Filename:="\\Server\users\Susan\My Documents
\Miscellaneous\Excel Help\Macro Projects-Excel\RPC Book1.xls"
'open the correct worksheet by month
Call MonthNumber
Call Select_Sheet
Set wbMyRPC = ActiveWorkbook
Set wsMyRPCSheet = ActiveSheet
'go thru all the checkboxes & copy if needed
If UserForm1.chkTotal.Value = True Then
myProgram = UserForm1.chkTotal.Caption
Call ActualCopy
End If
If UserForm1.chkAHC06.Value = True Then
myProgram = UserForm1.chkAHC06.Caption
Call ActualCopy
End If
If UserForm1.chkDANC05.Value = True Then
myProgram = UserForm1.chkDANC05.Caption
Call ActualCopy
End If
'If UserForm1.chkHPG05.Value = True Then
'myProgram = UserForm1.chkHPG05.Caption
'Call ActualCopy
'End If
If Userform1.chkHPG06.Value = True Then
myProgram = UserForm1.chkHPG06.Caption
Call ActualCopy
End If
If UserForm1.chkLCHOME05.Value = True Then
myProgram = UserForm1.chkLCHOME05.Caption
Call ActualCopy
End If
If UserForm1.chkCHDO06.Value = True Then
myProgram = UserForm1.chkCHDO06.Caption
Call ActualCopy
End If
'If UserForm1.chkCro.Value = True Then
'myProgram = UserForm1.chkCro.Caption
'Call ActualCopy
'End If
If UserForm1.chkLCHBYR05.Value = True Then
myProgram = UserForm1.chkLCHBYR05.Caption
Call ActualCopy
End If
If UserForm1.chkMicro.Value = True Then
myProgram = UserForm1.chkMicro.Caption
Call ActualCopy
End If
'If Userform1.chkAccess.Value = True Then
'myProgram = UserForm1.chkAccess.Caption
'Call ActualCopy
'End If
If UserForm1.chkRentals.Value = True Then
myProgram = UserForm1.chkRentals.Caption
Call ActualCopy
End If
If UserForm1.chkRPC.Value = True Then
myProgram = UserForm1.chkRPC.Caption
Call ActualCopy
End If
'after all values exported, save both workbooks
'check if keepopen chkbox is true
'if not, close wbMyRPC
Call Overhead
rReturn.Select
If UserForm1.chkKeepOpen.Value = False Then
Application.DisplayAlerts = False
wbMyRPC.Save
wbMyRPC.Close
Application.DisplayAlerts = True
End If
wbMyInvoices.Save
End Sub
=============================