Excel sheets with employees and dates
$begingroup$
I have more than 20 sheets in Excel and one main sheet (all programs with 200 names). Each sheet has a column with names and 24 months (Jan 18 to Dec 18, Jan 19 to Dec 20). Each sheet names is a subset of the main sheet.
Main sheet (all programs) has 200 names and 24 months (values to be calculated based on other sheets). The other sheet has names and values for each month respective to the main sheet. I need to take each name in main sheet and search the name in all other sheets, and if present sum all same column values and insert in the main sheet.
For 1 name I need to do calculation on 34 cells (for 200 names * 34 cells = 6800 cells). It's taking almost 20 minutes with my code. Is there any other way I can do it or any modification which improves the performance?
Main Sheet has name "employee1"
Sheet1
Sheet2
Value on the main sheet should be calculated respect to months
Dim sheetCount As Integer
Dim datatoFind
Private Sub CommandButton1_Click()
Dim mainSheet As String: mainSheet = "All Programs"
Dim nameColumnStart As String: nameColumnStart = "A"
Dim namesStart As Integer: namesStart = 1
Dim namesEnd As Integer: namesEnd = 200
Dim startColumn As Integer: startColumn = 10 'J Column'
Dim EndColumn As Integer: EndColumn = 33 'AG Column'
namesStart = InputBox("Please enter start value")
namesEnd = InputBox("Please enter end value")
Dim temp_str As String
Dim total As Single
On Error Resume Next
Sheets(mainSheet).Activate
lastRow_main = ActiveCell.SpecialCells(xlLastCell).Row
lastCol_main = 34
For vRow = namesStart To namesEnd
temp_str = Sheets(mainSheet).Cells(vRow, "A").Text
datatoFind = StrConv(temp_str, vbLowerCase)
For vCol = startColumn To EndColumn
total = Find_Data(vCol)
Worksheets(mainSheet).Cells(vRow, vCol).Value = total
Next vCol
Next vRow
Sheets(mainSheet).Activate
'MsgBox ("Calculated all values")'
End Sub
Private Function Find_Data(ByVal ColumnName As Integer) As Single
Dim counter As Integer
Dim currentSheet As Integer
Dim sheetCount As Integer
Dim str As String
Dim lastRow As Long
Dim lastCol As Long
Dim val As Single
Find_Data = 0
currentSheet = ActiveSheet.Index
If datatoFind = "" Then Exit Function
sheetCount = ActiveWorkbook.Sheets.Count
For counter = 2 To sheetCount
Sheets(counter).Activate
lastRow = ActiveCell.SpecialCells(xlLastCell).Row
lastCol = ActiveCell.SpecialCells(xlLastCell).Column
For vRow = 1 To lastRow
str = Sheets(counter).Cells(vRow, "A").Text
If InStr(1, StrConv(str, vbLowerCase), datatoFind) Then
val = Sheets(counter).Cells(vRow, ColumnName).Value
Find_Data = Find_Data + val
End If
Next vRow
Next counter
End Function
performance vba excel
New contributor
$endgroup$
add a comment |
$begingroup$
I have more than 20 sheets in Excel and one main sheet (all programs with 200 names). Each sheet has a column with names and 24 months (Jan 18 to Dec 18, Jan 19 to Dec 20). Each sheet names is a subset of the main sheet.
Main sheet (all programs) has 200 names and 24 months (values to be calculated based on other sheets). The other sheet has names and values for each month respective to the main sheet. I need to take each name in main sheet and search the name in all other sheets, and if present sum all same column values and insert in the main sheet.
For 1 name I need to do calculation on 34 cells (for 200 names * 34 cells = 6800 cells). It's taking almost 20 minutes with my code. Is there any other way I can do it or any modification which improves the performance?
Main Sheet has name "employee1"
Sheet1
Sheet2
Value on the main sheet should be calculated respect to months
Dim sheetCount As Integer
Dim datatoFind
Private Sub CommandButton1_Click()
Dim mainSheet As String: mainSheet = "All Programs"
Dim nameColumnStart As String: nameColumnStart = "A"
Dim namesStart As Integer: namesStart = 1
Dim namesEnd As Integer: namesEnd = 200
Dim startColumn As Integer: startColumn = 10 'J Column'
Dim EndColumn As Integer: EndColumn = 33 'AG Column'
namesStart = InputBox("Please enter start value")
namesEnd = InputBox("Please enter end value")
Dim temp_str As String
Dim total As Single
On Error Resume Next
Sheets(mainSheet).Activate
lastRow_main = ActiveCell.SpecialCells(xlLastCell).Row
lastCol_main = 34
For vRow = namesStart To namesEnd
temp_str = Sheets(mainSheet).Cells(vRow, "A").Text
datatoFind = StrConv(temp_str, vbLowerCase)
For vCol = startColumn To EndColumn
total = Find_Data(vCol)
Worksheets(mainSheet).Cells(vRow, vCol).Value = total
Next vCol
Next vRow
Sheets(mainSheet).Activate
'MsgBox ("Calculated all values")'
End Sub
Private Function Find_Data(ByVal ColumnName As Integer) As Single
Dim counter As Integer
Dim currentSheet As Integer
Dim sheetCount As Integer
Dim str As String
Dim lastRow As Long
Dim lastCol As Long
Dim val As Single
Find_Data = 0
currentSheet = ActiveSheet.Index
If datatoFind = "" Then Exit Function
sheetCount = ActiveWorkbook.Sheets.Count
For counter = 2 To sheetCount
Sheets(counter).Activate
lastRow = ActiveCell.SpecialCells(xlLastCell).Row
lastCol = ActiveCell.SpecialCells(xlLastCell).Column
For vRow = 1 To lastRow
str = Sheets(counter).Cells(vRow, "A").Text
If InStr(1, StrConv(str, vbLowerCase), datatoFind) Then
val = Sheets(counter).Cells(vRow, ColumnName).Value
Find_Data = Find_Data + val
End If
Next vRow
Next counter
End Function
performance vba excel
New contributor
$endgroup$
3
$begingroup$
Welcome to Code Review! The current question title, which states your concerns about the code, applies to too many questions on this site to be useful. The site standard is for the title to simply state the task accomplished by the code. Please see How to Ask for examples, and revise the title accordingly.
$endgroup$
– Toby Speight
9 hours ago
2
$begingroup$
I've removed the VBScript tag, since this is obviously VBA - and VBScript is a different language. What Toby means is that as it stands, the post's title is essentially "my code runs too slow, how do I make it faster" - which is a title that's applicable to pretty much 90% of the VBA questions on this site. So in order to avoid having a vba page filled with nearly-identical titles, we ask that you make your title a short description of what your code does, i.e. it's purpose. As the watermark says: "state the purpose of the code". Thanks
$endgroup$
– Mathieu Guindon
9 hours ago
$begingroup$
i changed the title for easy filtering . Thank you @m
$endgroup$
– Rohith Gowda
9 hours ago
2
$begingroup$
That's.... literally the opposite of what I said.
$endgroup$
– Mathieu Guindon
9 hours ago
$begingroup$
Got it , I will change lol
$endgroup$
– Rohith Gowda
2 hours ago
add a comment |
$begingroup$
I have more than 20 sheets in Excel and one main sheet (all programs with 200 names). Each sheet has a column with names and 24 months (Jan 18 to Dec 18, Jan 19 to Dec 20). Each sheet names is a subset of the main sheet.
Main sheet (all programs) has 200 names and 24 months (values to be calculated based on other sheets). The other sheet has names and values for each month respective to the main sheet. I need to take each name in main sheet and search the name in all other sheets, and if present sum all same column values and insert in the main sheet.
For 1 name I need to do calculation on 34 cells (for 200 names * 34 cells = 6800 cells). It's taking almost 20 minutes with my code. Is there any other way I can do it or any modification which improves the performance?
Main Sheet has name "employee1"
Sheet1
Sheet2
Value on the main sheet should be calculated respect to months
Dim sheetCount As Integer
Dim datatoFind
Private Sub CommandButton1_Click()
Dim mainSheet As String: mainSheet = "All Programs"
Dim nameColumnStart As String: nameColumnStart = "A"
Dim namesStart As Integer: namesStart = 1
Dim namesEnd As Integer: namesEnd = 200
Dim startColumn As Integer: startColumn = 10 'J Column'
Dim EndColumn As Integer: EndColumn = 33 'AG Column'
namesStart = InputBox("Please enter start value")
namesEnd = InputBox("Please enter end value")
Dim temp_str As String
Dim total As Single
On Error Resume Next
Sheets(mainSheet).Activate
lastRow_main = ActiveCell.SpecialCells(xlLastCell).Row
lastCol_main = 34
For vRow = namesStart To namesEnd
temp_str = Sheets(mainSheet).Cells(vRow, "A").Text
datatoFind = StrConv(temp_str, vbLowerCase)
For vCol = startColumn To EndColumn
total = Find_Data(vCol)
Worksheets(mainSheet).Cells(vRow, vCol).Value = total
Next vCol
Next vRow
Sheets(mainSheet).Activate
'MsgBox ("Calculated all values")'
End Sub
Private Function Find_Data(ByVal ColumnName As Integer) As Single
Dim counter As Integer
Dim currentSheet As Integer
Dim sheetCount As Integer
Dim str As String
Dim lastRow As Long
Dim lastCol As Long
Dim val As Single
Find_Data = 0
currentSheet = ActiveSheet.Index
If datatoFind = "" Then Exit Function
sheetCount = ActiveWorkbook.Sheets.Count
For counter = 2 To sheetCount
Sheets(counter).Activate
lastRow = ActiveCell.SpecialCells(xlLastCell).Row
lastCol = ActiveCell.SpecialCells(xlLastCell).Column
For vRow = 1 To lastRow
str = Sheets(counter).Cells(vRow, "A").Text
If InStr(1, StrConv(str, vbLowerCase), datatoFind) Then
val = Sheets(counter).Cells(vRow, ColumnName).Value
Find_Data = Find_Data + val
End If
Next vRow
Next counter
End Function
performance vba excel
New contributor
$endgroup$
I have more than 20 sheets in Excel and one main sheet (all programs with 200 names). Each sheet has a column with names and 24 months (Jan 18 to Dec 18, Jan 19 to Dec 20). Each sheet names is a subset of the main sheet.
Main sheet (all programs) has 200 names and 24 months (values to be calculated based on other sheets). The other sheet has names and values for each month respective to the main sheet. I need to take each name in main sheet and search the name in all other sheets, and if present sum all same column values and insert in the main sheet.
For 1 name I need to do calculation on 34 cells (for 200 names * 34 cells = 6800 cells). It's taking almost 20 minutes with my code. Is there any other way I can do it or any modification which improves the performance?
Main Sheet has name "employee1"
Sheet1
Sheet2
Value on the main sheet should be calculated respect to months
Dim sheetCount As Integer
Dim datatoFind
Private Sub CommandButton1_Click()
Dim mainSheet As String: mainSheet = "All Programs"
Dim nameColumnStart As String: nameColumnStart = "A"
Dim namesStart As Integer: namesStart = 1
Dim namesEnd As Integer: namesEnd = 200
Dim startColumn As Integer: startColumn = 10 'J Column'
Dim EndColumn As Integer: EndColumn = 33 'AG Column'
namesStart = InputBox("Please enter start value")
namesEnd = InputBox("Please enter end value")
Dim temp_str As String
Dim total As Single
On Error Resume Next
Sheets(mainSheet).Activate
lastRow_main = ActiveCell.SpecialCells(xlLastCell).Row
lastCol_main = 34
For vRow = namesStart To namesEnd
temp_str = Sheets(mainSheet).Cells(vRow, "A").Text
datatoFind = StrConv(temp_str, vbLowerCase)
For vCol = startColumn To EndColumn
total = Find_Data(vCol)
Worksheets(mainSheet).Cells(vRow, vCol).Value = total
Next vCol
Next vRow
Sheets(mainSheet).Activate
'MsgBox ("Calculated all values")'
End Sub
Private Function Find_Data(ByVal ColumnName As Integer) As Single
Dim counter As Integer
Dim currentSheet As Integer
Dim sheetCount As Integer
Dim str As String
Dim lastRow As Long
Dim lastCol As Long
Dim val As Single
Find_Data = 0
currentSheet = ActiveSheet.Index
If datatoFind = "" Then Exit Function
sheetCount = ActiveWorkbook.Sheets.Count
For counter = 2 To sheetCount
Sheets(counter).Activate
lastRow = ActiveCell.SpecialCells(xlLastCell).Row
lastCol = ActiveCell.SpecialCells(xlLastCell).Column
For vRow = 1 To lastRow
str = Sheets(counter).Cells(vRow, "A").Text
If InStr(1, StrConv(str, vbLowerCase), datatoFind) Then
val = Sheets(counter).Cells(vRow, ColumnName).Value
Find_Data = Find_Data + val
End If
Next vRow
Next counter
End Function
performance vba excel
performance vba excel
New contributor
New contributor
edited 5 mins ago
Jamal♦
30.3k11116226
30.3k11116226
New contributor
asked 9 hours ago
Rohith GowdaRohith Gowda
13
13
New contributor
New contributor
3
$begingroup$
Welcome to Code Review! The current question title, which states your concerns about the code, applies to too many questions on this site to be useful. The site standard is for the title to simply state the task accomplished by the code. Please see How to Ask for examples, and revise the title accordingly.
$endgroup$
– Toby Speight
9 hours ago
2
$begingroup$
I've removed the VBScript tag, since this is obviously VBA - and VBScript is a different language. What Toby means is that as it stands, the post's title is essentially "my code runs too slow, how do I make it faster" - which is a title that's applicable to pretty much 90% of the VBA questions on this site. So in order to avoid having a vba page filled with nearly-identical titles, we ask that you make your title a short description of what your code does, i.e. it's purpose. As the watermark says: "state the purpose of the code". Thanks
$endgroup$
– Mathieu Guindon
9 hours ago
$begingroup$
i changed the title for easy filtering . Thank you @m
$endgroup$
– Rohith Gowda
9 hours ago
2
$begingroup$
That's.... literally the opposite of what I said.
$endgroup$
– Mathieu Guindon
9 hours ago
$begingroup$
Got it , I will change lol
$endgroup$
– Rohith Gowda
2 hours ago
add a comment |
3
$begingroup$
Welcome to Code Review! The current question title, which states your concerns about the code, applies to too many questions on this site to be useful. The site standard is for the title to simply state the task accomplished by the code. Please see How to Ask for examples, and revise the title accordingly.
$endgroup$
– Toby Speight
9 hours ago
2
$begingroup$
I've removed the VBScript tag, since this is obviously VBA - and VBScript is a different language. What Toby means is that as it stands, the post's title is essentially "my code runs too slow, how do I make it faster" - which is a title that's applicable to pretty much 90% of the VBA questions on this site. So in order to avoid having a vba page filled with nearly-identical titles, we ask that you make your title a short description of what your code does, i.e. it's purpose. As the watermark says: "state the purpose of the code". Thanks
$endgroup$
– Mathieu Guindon
9 hours ago
$begingroup$
i changed the title for easy filtering . Thank you @m
$endgroup$
– Rohith Gowda
9 hours ago
2
$begingroup$
That's.... literally the opposite of what I said.
$endgroup$
– Mathieu Guindon
9 hours ago
$begingroup$
Got it , I will change lol
$endgroup$
– Rohith Gowda
2 hours ago
3
3
$begingroup$
Welcome to Code Review! The current question title, which states your concerns about the code, applies to too many questions on this site to be useful. The site standard is for the title to simply state the task accomplished by the code. Please see How to Ask for examples, and revise the title accordingly.
$endgroup$
– Toby Speight
9 hours ago
$begingroup$
Welcome to Code Review! The current question title, which states your concerns about the code, applies to too many questions on this site to be useful. The site standard is for the title to simply state the task accomplished by the code. Please see How to Ask for examples, and revise the title accordingly.
$endgroup$
– Toby Speight
9 hours ago
2
2
$begingroup$
I've removed the VBScript tag, since this is obviously VBA - and VBScript is a different language. What Toby means is that as it stands, the post's title is essentially "my code runs too slow, how do I make it faster" - which is a title that's applicable to pretty much 90% of the VBA questions on this site. So in order to avoid having a vba page filled with nearly-identical titles, we ask that you make your title a short description of what your code does, i.e. it's purpose. As the watermark says: "state the purpose of the code". Thanks
$endgroup$
– Mathieu Guindon
9 hours ago
$begingroup$
I've removed the VBScript tag, since this is obviously VBA - and VBScript is a different language. What Toby means is that as it stands, the post's title is essentially "my code runs too slow, how do I make it faster" - which is a title that's applicable to pretty much 90% of the VBA questions on this site. So in order to avoid having a vba page filled with nearly-identical titles, we ask that you make your title a short description of what your code does, i.e. it's purpose. As the watermark says: "state the purpose of the code". Thanks
$endgroup$
– Mathieu Guindon
9 hours ago
$begingroup$
i changed the title for easy filtering . Thank you @m
$endgroup$
– Rohith Gowda
9 hours ago
$begingroup$
i changed the title for easy filtering . Thank you @m
$endgroup$
– Rohith Gowda
9 hours ago
2
2
$begingroup$
That's.... literally the opposite of what I said.
$endgroup$
– Mathieu Guindon
9 hours ago
$begingroup$
That's.... literally the opposite of what I said.
$endgroup$
– Mathieu Guindon
9 hours ago
$begingroup$
Got it , I will change lol
$endgroup$
– Rohith Gowda
2 hours ago
$begingroup$
Got it , I will change lol
$endgroup$
– Rohith Gowda
2 hours ago
add a comment |
0
active
oldest
votes
Your Answer
StackExchange.ifUsing("editor", function () {
return StackExchange.using("mathjaxEditing", function () {
StackExchange.MarkdownEditor.creationCallbacks.add(function (editor, postfix) {
StackExchange.mathjaxEditing.prepareWmdForMathJax(editor, postfix, [["\$", "\$"]]);
});
});
}, "mathjax-editing");
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "196"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Rohith Gowda is a new contributor. Be nice, and check out our Code of Conduct.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcodereview.stackexchange.com%2fquestions%2f211938%2fexcel-sheets-with-employees-and-dates%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
0
active
oldest
votes
0
active
oldest
votes
active
oldest
votes
active
oldest
votes
Rohith Gowda is a new contributor. Be nice, and check out our Code of Conduct.
Rohith Gowda is a new contributor. Be nice, and check out our Code of Conduct.
Rohith Gowda is a new contributor. Be nice, and check out our Code of Conduct.
Rohith Gowda is a new contributor. Be nice, and check out our Code of Conduct.
Thanks for contributing an answer to Code Review Stack Exchange!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
Use MathJax to format equations. MathJax reference.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcodereview.stackexchange.com%2fquestions%2f211938%2fexcel-sheets-with-employees-and-dates%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
3
$begingroup$
Welcome to Code Review! The current question title, which states your concerns about the code, applies to too many questions on this site to be useful. The site standard is for the title to simply state the task accomplished by the code. Please see How to Ask for examples, and revise the title accordingly.
$endgroup$
– Toby Speight
9 hours ago
2
$begingroup$
I've removed the VBScript tag, since this is obviously VBA - and VBScript is a different language. What Toby means is that as it stands, the post's title is essentially "my code runs too slow, how do I make it faster" - which is a title that's applicable to pretty much 90% of the VBA questions on this site. So in order to avoid having a vba page filled with nearly-identical titles, we ask that you make your title a short description of what your code does, i.e. it's purpose. As the watermark says: "state the purpose of the code". Thanks
$endgroup$
– Mathieu Guindon
9 hours ago
$begingroup$
i changed the title for easy filtering . Thank you @m
$endgroup$
– Rohith Gowda
9 hours ago
2
$begingroup$
That's.... literally the opposite of what I said.
$endgroup$
– Mathieu Guindon
9 hours ago
$begingroup$
Got it , I will change lol
$endgroup$
– Rohith Gowda
2 hours ago