J
Jim A
Hi - I have been working on some Macros. I am compiling a macro that runs
other macros. I have two noticeable problems.
1 - My SaveAs macro runs fine by itself. But when called or ran by another
macro, (which calls more than one macro) the SaveAs macro it stops.
2- Many of my macros, when ran by another macro (which runs more than one
macro) cycles through twice.
My specific question is about no. 2 and the following are the individual
macros and the macro that runs them.
Sub Store_Data_to_ValueSheets_Part1()
'''''This macro copies values from sheets 1, 2, 3, 4, and Credit
History''''''''
''''' NOT TO BE RUN INDEPENDENTLY - FOR THERE MUST EXIST A FOLDER
(n1)''''''''''''
MsgBox "inside StoreData Part1 macro"
'Turning calculationa and screen updating off for better performance
Application.ScreenUpdating = False
Application.Calculation = xlCalculationManual
'setting Dim
Dim ws1 As Worksheet, ws2 As Worksheet, ws3 As Worksheet, ws4 As Worksheet
Dim wsch As Worksheet
Dim Nws As Worksheet
Dim n1 As String
'n1 is students name
n1 = Sheets("1").Range("B1").Value
'hide worksheet
'Worksheets(n1).Visible = False
'defining variable to worksheets
Set ws1 = ThisWorkbook.Sheets("1")
Set ws2 = ThisWorkbook.Sheets("2")
Set ws3 = ThisWorkbook.Sheets("3")
Set ws4 = ThisWorkbook.Sheets("4")
Set wsch = ThisWorkbook.Sheets("Credit History")
Set Nws = ThisWorkbook.Sheets(n1)
''''''''''''''''''''''''''Copy Code'''''''''''''''''''''''''''''''''''''
Dim i As Long, j As Long, k As Long
k = 0
j = 0
For i = 1 To 10
'copy values for sheets 1
Nws.Range("A2:A44").Offset(, j).Value = _
ws1.Range("E5:E47").Offset(, k).Value
'copy values for sheets 2
Nws.Range("P244").Offset(, j).Value = _
ws2.Range("E5:E47").Offset(, k).Value
'copy values for sheets 3
Nws.Range("A46:A88").Offset(, j).Value = _
ws3.Range("E5:E47").Offset(, k).Value
'copy values for sheets 4
Nws.Range("P4688").Offset(, j).Value = _
ws4.Range("E5:E47").Offset(, k).Value
k = k + 3
j = j + 1
Next i
'Turning calculation and screen updating back on
Application.Calculation = xlCalculationAutomatic
Application.ScreenUpdating = True
MsgBox "completed part1"
End Sub
THE OTHER -
Sub Store_Data_to_ValueSheets_Part2()
'''''This macro copies values from sheets 1, 2, 3, 4, and Credit
History'''''''
''''' NOT TO BE RUN INDEPENDENTLY - FOR THERE MUST EXIST A FOLDER
(n1)''''''''''''
MsgBox "inside StoreData Part2 macro"
'Turning calculationa and screen updating off for better performance
Application.ScreenUpdating = False
Application.Calculation = xlCalculationManual
'setting Dim
Dim ws1 As Worksheet, ws2 As Worksheet, ws3 As Worksheet, ws4 As Worksheet
Dim wsch As Worksheet
Dim Nws As Worksheet
Dim n1 As String
'n1 is students name
n1 = Sheets("1").Range("B1").Value
'hide worksheet
Worksheets(n1).Visible = False
'defining variable to worksheets
Set ws1 = ThisWorkbook.Sheets("1")
Set ws2 = ThisWorkbook.Sheets("2")
Set ws3 = ThisWorkbook.Sheets("3")
Set ws4 = ThisWorkbook.Sheets("4")
Set wsch = ThisWorkbook.Sheets("Credit History")
Set Nws = ThisWorkbook.Sheets(n1)
'copy parts of sheets 1, 2, 3 and 4 that did not fit parameters above
Dim m As Long, n As Long
m = 0
For n = 1 To 2
'copy part of sheet 1
Nws.Range("K2:K44").Offset(, m).Value = _
ws1.Range("AI5:AI47").Offset(, m).Value
Nws.Range("M2:M44").Offset(, m).Value = _
ws1.Range("AL5:AL47").Offset(, m).Value
'copy part of sheet 2
Nws.Range("Z2:Z44").Offset(, m).Value = _
ws2.Range("AI5:AI47").Offset(, m).Value
Nws.Range("AB2:AB44").Offset(, m).Value = _
ws2.Range("AL5:AL47").Offset(, m).Value
'copy part of sheet 3
Nws.Range("K46:K88").Offset(, m).Value = _
ws3.Range("AI5:AI47").Offset(, m).Value
Nws.Range("M46:M88").Offset(, m).Value = _
ws3.Range("AL5:AL47").Offset(, m).Value
'copy part of sheet 4
Nws.Range("Z46:Z88").Offset(, m).Value = _
ws4.Range("AI5:AI47").Offset(, m).Value
Nws.Range("AB46:AB88").Offset(, m).Value = _
ws4.Range("AL5:AL47").Offset(, m).Value
m = m + 1
Next n
''''copy value back to sheets Credit History'''''
Nws.Range("A90:X132").Value = _
wsch.Range("D6:AA48").Value
'Turning calculation and screen updating back on
Application.Calculation = xlCalculationAutomatic
Application.ScreenUpdating = True
MsgBox "completed part 2"
End Sub
This is the macro that runs them -
Sub Store_Data_Part1_and_2()
Run [Store_Data_to_ValueSheets_Part1()]
Run [Store_Data_to_ValueSheets_Part2()]
End Sub
Thanks for any help - Jim A
other macros. I have two noticeable problems.
1 - My SaveAs macro runs fine by itself. But when called or ran by another
macro, (which calls more than one macro) the SaveAs macro it stops.
2- Many of my macros, when ran by another macro (which runs more than one
macro) cycles through twice.
My specific question is about no. 2 and the following are the individual
macros and the macro that runs them.
Sub Store_Data_to_ValueSheets_Part1()
'''''This macro copies values from sheets 1, 2, 3, 4, and Credit
History''''''''
''''' NOT TO BE RUN INDEPENDENTLY - FOR THERE MUST EXIST A FOLDER
(n1)''''''''''''
MsgBox "inside StoreData Part1 macro"
'Turning calculationa and screen updating off for better performance
Application.ScreenUpdating = False
Application.Calculation = xlCalculationManual
'setting Dim
Dim ws1 As Worksheet, ws2 As Worksheet, ws3 As Worksheet, ws4 As Worksheet
Dim wsch As Worksheet
Dim Nws As Worksheet
Dim n1 As String
'n1 is students name
n1 = Sheets("1").Range("B1").Value
'hide worksheet
'Worksheets(n1).Visible = False
'defining variable to worksheets
Set ws1 = ThisWorkbook.Sheets("1")
Set ws2 = ThisWorkbook.Sheets("2")
Set ws3 = ThisWorkbook.Sheets("3")
Set ws4 = ThisWorkbook.Sheets("4")
Set wsch = ThisWorkbook.Sheets("Credit History")
Set Nws = ThisWorkbook.Sheets(n1)
''''''''''''''''''''''''''Copy Code'''''''''''''''''''''''''''''''''''''
Dim i As Long, j As Long, k As Long
k = 0
j = 0
For i = 1 To 10
'copy values for sheets 1
Nws.Range("A2:A44").Offset(, j).Value = _
ws1.Range("E5:E47").Offset(, k).Value
'copy values for sheets 2
Nws.Range("P244").Offset(, j).Value = _
ws2.Range("E5:E47").Offset(, k).Value
'copy values for sheets 3
Nws.Range("A46:A88").Offset(, j).Value = _
ws3.Range("E5:E47").Offset(, k).Value
'copy values for sheets 4
Nws.Range("P4688").Offset(, j).Value = _
ws4.Range("E5:E47").Offset(, k).Value
k = k + 3
j = j + 1
Next i
'Turning calculation and screen updating back on
Application.Calculation = xlCalculationAutomatic
Application.ScreenUpdating = True
MsgBox "completed part1"
End Sub
THE OTHER -
Sub Store_Data_to_ValueSheets_Part2()
'''''This macro copies values from sheets 1, 2, 3, 4, and Credit
History'''''''
''''' NOT TO BE RUN INDEPENDENTLY - FOR THERE MUST EXIST A FOLDER
(n1)''''''''''''
MsgBox "inside StoreData Part2 macro"
'Turning calculationa and screen updating off for better performance
Application.ScreenUpdating = False
Application.Calculation = xlCalculationManual
'setting Dim
Dim ws1 As Worksheet, ws2 As Worksheet, ws3 As Worksheet, ws4 As Worksheet
Dim wsch As Worksheet
Dim Nws As Worksheet
Dim n1 As String
'n1 is students name
n1 = Sheets("1").Range("B1").Value
'hide worksheet
Worksheets(n1).Visible = False
'defining variable to worksheets
Set ws1 = ThisWorkbook.Sheets("1")
Set ws2 = ThisWorkbook.Sheets("2")
Set ws3 = ThisWorkbook.Sheets("3")
Set ws4 = ThisWorkbook.Sheets("4")
Set wsch = ThisWorkbook.Sheets("Credit History")
Set Nws = ThisWorkbook.Sheets(n1)
'copy parts of sheets 1, 2, 3 and 4 that did not fit parameters above
Dim m As Long, n As Long
m = 0
For n = 1 To 2
'copy part of sheet 1
Nws.Range("K2:K44").Offset(, m).Value = _
ws1.Range("AI5:AI47").Offset(, m).Value
Nws.Range("M2:M44").Offset(, m).Value = _
ws1.Range("AL5:AL47").Offset(, m).Value
'copy part of sheet 2
Nws.Range("Z2:Z44").Offset(, m).Value = _
ws2.Range("AI5:AI47").Offset(, m).Value
Nws.Range("AB2:AB44").Offset(, m).Value = _
ws2.Range("AL5:AL47").Offset(, m).Value
'copy part of sheet 3
Nws.Range("K46:K88").Offset(, m).Value = _
ws3.Range("AI5:AI47").Offset(, m).Value
Nws.Range("M46:M88").Offset(, m).Value = _
ws3.Range("AL5:AL47").Offset(, m).Value
'copy part of sheet 4
Nws.Range("Z46:Z88").Offset(, m).Value = _
ws4.Range("AI5:AI47").Offset(, m).Value
Nws.Range("AB46:AB88").Offset(, m).Value = _
ws4.Range("AL5:AL47").Offset(, m).Value
m = m + 1
Next n
''''copy value back to sheets Credit History'''''
Nws.Range("A90:X132").Value = _
wsch.Range("D6:AA48").Value
'Turning calculation and screen updating back on
Application.Calculation = xlCalculationAutomatic
Application.ScreenUpdating = True
MsgBox "completed part 2"
End Sub
This is the macro that runs them -
Sub Store_Data_Part1_and_2()
Run [Store_Data_to_ValueSheets_Part1()]
Run [Store_Data_to_ValueSheets_Part2()]
End Sub
Thanks for any help - Jim A