Bullsandbears123
Technical User
I have the following code, that I run in a Macro in Excel. I would like to change it so I can run it from MS Access VBA, how can I change the code to do this?
Thanks
________________________________________________________
Function BuildMonthlyPage()
'set Variables for Worksheets
Dim sheet1 As String
Dim Sheet2 As String
'define worksheets variables
sheet1 = "Daily" ' Data source page comes from Access
Sheet2 = "Monthly" ' Named of monthly form page
'makes new worksheet
Worksheets.Add
Worksheets("sheet1"
.Name = Sheet2
'Set page to Time Roman and 10pt
Worksheets(Sheet2).Range("a1:f50"
.Font.Name = "Times New Roman"
Worksheets(Sheet2).Range("a1:f50"
.Font.Size = 10
' Merge Title Cells and set formats
With Worksheets(Sheet2)
.Range("a1:f1"
.Merge
.Range("a3:f3"
.Merge
.Range("a4:f4"
.Merge
'Set formats
.Range("a1:f1"
.Font.Size = 14
.Range("a1:f1"
.Font.Bold = True
.Range("a3:f3"
.Font.Size = 14
.Range("a3:f3"
.Font.Bold = True
.Range("a4:f4"
.Font.Size = 14
.Range("a4:f4"
.Font.Bold = True
End With
'Set start Borders
With Worksheets(Sheet2)
.Range("a4:f4"
.BorderAround Weight:=xlMedium ' date
End With
'set End Borders
'Set Titles for Form
With Worksheets(Sheet2)
.Cells(1, 1).Value = "the Title"
End With
'End Setting Titles for Form
'Setting Variables to grab data
'Performance
Dim net As String
'End setting Variables to grab data
'Grab data
'Performance
net = Worksheets(sheet1).Cells(3, 1).Value
'Place Data
'Performance
Worksheets(Sheet2).Cells(8, 2).Value = net
Worksheets(Sheet2).Cells(9, 2).Value = longside
Worksheets(Sheet2).Cells(10, 2).Value = shortside
'End place data
'**********************************************************
'START OF GRAB AND PLACE ESTIMATE
'Define variables for Estimate
Dim rcnt As Integer
Dim ccnt As Integer
Dim tag As String
Dim tcnt As Integer
Dim Label As String
Dim counter As Integer
Dim refer As String
Dim Acnt As Integer
Dim percent As Double
Dim rcnth As Integer
rcnt = 1
ccnt = 1
tcnt = 1
Label = "Text77"
Do Until tag = Label Or tcnt > 99
tag = Worksheets(sheet1).Cells(rcnt, ccnt).Value
Do Until ccnt = 50 Or tag = Label
ccnt = ccnt + 1
tag = Worksheets(sheet1).Cells(rcnt, ccnt).Value
rcnt = 1
Do Until rcnt = 50 Or tag = Label
rcnt = rcnt + 1
tag = Worksheets(sheet1).Cells(rcnt, ccnt).Value
Loop
Loop
tcnt = rcnt + rcnt
Loop
'holds place for 1st estimate
rcnth = rcnt + 1
'Changes text in data page to Number
counter = 1
Do Until counter > 7
week1 = Worksheets(sheet1).Cells(rcnt, ccnt).Value
Worksheets(sheet1).Cells(rcnt, ccnt).Value = week1
week1 = Worksheets(sheet1).Cells(rcnt, ccnt).Value
rcnt = rcnt + 1
counter = counter + 1
Loop
rcnt = rcnth
'set place on atlas page
Acnt = 8
week1 = Worksheets(sheet1).Cells(rcnt, ccnt).Value
'place data of estimate
Do While IsNumeric(week1)
'Grab and place data
week1 = Worksheets(sheet1).Cells(rcnt, ccnt).Value
Worksheets(Sheet2).Cells(Acnt, 5).Value = week1
'moves to next estimate
Acnt = Acnt + 1
rcnt = rcnt + 1
'Sets week1 so not to paste last none Number
week1 = Worksheets(sheet1).Cells(rcnt, ccnt).Value
Loop
'END OF GRAB AND PLACE ESTIMATE
'********************************************************
'GRAB AND PLACE MARKET CAP
'Set Variables to ZERO
rcnt = 0
ccnt = 0
tag = ""
tcnt = 0
Label = ""
counter = 0
refer = ""
Acnt = 0 ' sets place for row on atlas
awcnta = 0 ' set place for column on atlas
percent = 0
rcnth = 0
rcnt = 1
ccnt = 1
tcnt = 1
Label = "Size"
Do Until tag = Label Or tcnt > 99
tag = Worksheets(sheet1).Cells(rcnt, ccnt).Value
Do Until ccnt = 50 Or tag = Label
ccnt = ccnt + 1
tag = Worksheets(sheet1).Cells(rcnt, ccnt).Value
rcnt = 1
Do Until rcnt = 50 Or tag = Label
rcnt = rcnt + 1
tag = Worksheets(sheet1).Cells(rcnt, ccnt).Value
Loop
Loop
tcnt = rcnt + rcnt
Loop
'holds place for 1st estimate
rcnth = rcnt + 1
rcnt = rcnth
'set place on monthly page
Acnt = 35
awcnt = 2
week1 = Worksheets(sheet1).Cells(rcnt, ccnt).Value
'Finds 1st item in Market Cap(size)
Do While week1 = ""
rcnt = rcnt + 1
week1 = Worksheets(sheet1).Cells(rcnt, ccnt).Value
Loop
'finds theplaces items until empty
Do Until week1 = ""
Select Case week1
Case Is = "Small"
refer = Worksheets(sheet1).Cells(rcnt, ccnt + 1).Value
Worksheets(Sheet2).Cells(35, 2).Value = refer
Case Is = "Mid"
refer = Worksheets(sheet1).Cells(rcnt, ccnt + 1).Value
Worksheets(Sheet2).Cells(36, 2).Value = refer
Case Is = "Large"
refer = Worksheets(sheet1).Cells(rcnt, ccnt + 1).Value
Worksheets(Sheet2).Cells(37, 2).Value = refer
End Select
rcnt = rcnt + 1
week1 = Worksheets(sheet1).Cells(rcnt, ccnt).Value
Loop
'Finds start of Short Sectors
Do While week1 = ""
rcnt = rcnt + 1
week1 = Worksheets(sheet1).Cells(rcnt, ccnt).Value
Loop
'finds the Short items until empty
Do Until week1 = ""
Select Case week1
Case Is = "Small"
refer = Worksheets(sheet1).Cells(rcnt, ccnt + 1).Value
Worksheets(Sheet2).Cells(35, 3).Value = refer
Case Is = "Mid"
refer = Worksheets(sheet1).Cells(rcnt, ccnt + 1).Value
Worksheets(Sheet2).Cells(36, 3).Value = refer
Case Is = "Large"
refer = Worksheets(sheet1).Cells(rcnt, ccnt + 1).Value
Worksheets(Sheet2).Cells(37, 3).Value = refer
End Select
rcnt = rcnt + 1
week1 = Worksheets(sheet1).Cells(rcnt, ccnt).Value
Loop
Format Page to monthly'With Cells(1, 1)
.Value = "Name of Title"
.Font.Bold = True
.Font.Size = 14
End With
Range("a1:c5"
.Interior.ColorIndex = 36
Range("a1:c5"
.BorderAround Weight:=xlThick
End Function
Thanks
________________________________________________________
Function BuildMonthlyPage()
'set Variables for Worksheets
Dim sheet1 As String
Dim Sheet2 As String
'define worksheets variables
sheet1 = "Daily" ' Data source page comes from Access
Sheet2 = "Monthly" ' Named of monthly form page
'makes new worksheet
Worksheets.Add
Worksheets("sheet1"
'Set page to Time Roman and 10pt
Worksheets(Sheet2).Range("a1:f50"
Worksheets(Sheet2).Range("a1:f50"
' Merge Title Cells and set formats
With Worksheets(Sheet2)
.Range("a1:f1"
.Range("a3:f3"
.Range("a4:f4"
'Set formats
.Range("a1:f1"
.Range("a1:f1"
.Range("a3:f3"
.Range("a3:f3"
.Range("a4:f4"
.Range("a4:f4"
End With
'Set start Borders
With Worksheets(Sheet2)
.Range("a4:f4"
End With
'set End Borders
'Set Titles for Form
With Worksheets(Sheet2)
.Cells(1, 1).Value = "the Title"
End With
'End Setting Titles for Form
'Setting Variables to grab data
'Performance
Dim net As String
'End setting Variables to grab data
'Grab data
'Performance
net = Worksheets(sheet1).Cells(3, 1).Value
'Place Data
'Performance
Worksheets(Sheet2).Cells(8, 2).Value = net
Worksheets(Sheet2).Cells(9, 2).Value = longside
Worksheets(Sheet2).Cells(10, 2).Value = shortside
'End place data
'**********************************************************
'START OF GRAB AND PLACE ESTIMATE
'Define variables for Estimate
Dim rcnt As Integer
Dim ccnt As Integer
Dim tag As String
Dim tcnt As Integer
Dim Label As String
Dim counter As Integer
Dim refer As String
Dim Acnt As Integer
Dim percent As Double
Dim rcnth As Integer
rcnt = 1
ccnt = 1
tcnt = 1
Label = "Text77"
Do Until tag = Label Or tcnt > 99
tag = Worksheets(sheet1).Cells(rcnt, ccnt).Value
Do Until ccnt = 50 Or tag = Label
ccnt = ccnt + 1
tag = Worksheets(sheet1).Cells(rcnt, ccnt).Value
rcnt = 1
Do Until rcnt = 50 Or tag = Label
rcnt = rcnt + 1
tag = Worksheets(sheet1).Cells(rcnt, ccnt).Value
Loop
Loop
tcnt = rcnt + rcnt
Loop
'holds place for 1st estimate
rcnth = rcnt + 1
'Changes text in data page to Number
counter = 1
Do Until counter > 7
week1 = Worksheets(sheet1).Cells(rcnt, ccnt).Value
Worksheets(sheet1).Cells(rcnt, ccnt).Value = week1
week1 = Worksheets(sheet1).Cells(rcnt, ccnt).Value
rcnt = rcnt + 1
counter = counter + 1
Loop
rcnt = rcnth
'set place on atlas page
Acnt = 8
week1 = Worksheets(sheet1).Cells(rcnt, ccnt).Value
'place data of estimate
Do While IsNumeric(week1)
'Grab and place data
week1 = Worksheets(sheet1).Cells(rcnt, ccnt).Value
Worksheets(Sheet2).Cells(Acnt, 5).Value = week1
'moves to next estimate
Acnt = Acnt + 1
rcnt = rcnt + 1
'Sets week1 so not to paste last none Number
week1 = Worksheets(sheet1).Cells(rcnt, ccnt).Value
Loop
'END OF GRAB AND PLACE ESTIMATE
'********************************************************
'GRAB AND PLACE MARKET CAP
'Set Variables to ZERO
rcnt = 0
ccnt = 0
tag = ""
tcnt = 0
Label = ""
counter = 0
refer = ""
Acnt = 0 ' sets place for row on atlas
awcnta = 0 ' set place for column on atlas
percent = 0
rcnth = 0
rcnt = 1
ccnt = 1
tcnt = 1
Label = "Size"
Do Until tag = Label Or tcnt > 99
tag = Worksheets(sheet1).Cells(rcnt, ccnt).Value
Do Until ccnt = 50 Or tag = Label
ccnt = ccnt + 1
tag = Worksheets(sheet1).Cells(rcnt, ccnt).Value
rcnt = 1
Do Until rcnt = 50 Or tag = Label
rcnt = rcnt + 1
tag = Worksheets(sheet1).Cells(rcnt, ccnt).Value
Loop
Loop
tcnt = rcnt + rcnt
Loop
'holds place for 1st estimate
rcnth = rcnt + 1
rcnt = rcnth
'set place on monthly page
Acnt = 35
awcnt = 2
week1 = Worksheets(sheet1).Cells(rcnt, ccnt).Value
'Finds 1st item in Market Cap(size)
Do While week1 = ""
rcnt = rcnt + 1
week1 = Worksheets(sheet1).Cells(rcnt, ccnt).Value
Loop
'finds theplaces items until empty
Do Until week1 = ""
Select Case week1
Case Is = "Small"
refer = Worksheets(sheet1).Cells(rcnt, ccnt + 1).Value
Worksheets(Sheet2).Cells(35, 2).Value = refer
Case Is = "Mid"
refer = Worksheets(sheet1).Cells(rcnt, ccnt + 1).Value
Worksheets(Sheet2).Cells(36, 2).Value = refer
Case Is = "Large"
refer = Worksheets(sheet1).Cells(rcnt, ccnt + 1).Value
Worksheets(Sheet2).Cells(37, 2).Value = refer
End Select
rcnt = rcnt + 1
week1 = Worksheets(sheet1).Cells(rcnt, ccnt).Value
Loop
'Finds start of Short Sectors
Do While week1 = ""
rcnt = rcnt + 1
week1 = Worksheets(sheet1).Cells(rcnt, ccnt).Value
Loop
'finds the Short items until empty
Do Until week1 = ""
Select Case week1
Case Is = "Small"
refer = Worksheets(sheet1).Cells(rcnt, ccnt + 1).Value
Worksheets(Sheet2).Cells(35, 3).Value = refer
Case Is = "Mid"
refer = Worksheets(sheet1).Cells(rcnt, ccnt + 1).Value
Worksheets(Sheet2).Cells(36, 3).Value = refer
Case Is = "Large"
refer = Worksheets(sheet1).Cells(rcnt, ccnt + 1).Value
Worksheets(Sheet2).Cells(37, 3).Value = refer
End Select
rcnt = rcnt + 1
week1 = Worksheets(sheet1).Cells(rcnt, ccnt).Value
Loop
Format Page to monthly'With Cells(1, 1)
.Value = "Name of Title"
.Font.Bold = True
.Font.Size = 14
End With
Range("a1:c5"
Range("a1:c5"
End Function