[Solved] Data Update Issue

Dear,

Kindly see the attached file;
Summary sheet has collection of certain data from each sheet in the worksheet.
1. When UPDATE button is clicked it updates whole data in the sheet. but i need to only add new record when new sheet is added and not to rewrite the whole data again in summary sheet. Kindly help
2. The "Batch" column is linked with each sheet to go directly to that particular sheet when clicked. It does not work for all the sheets ( last 02 sheets it does not work, while code is the same).

Regards,
 

Attachments

Dear,

Kindly see the attached file;
Summary sheet has collection of certain data from each sheet in the worksheet.
1. When UPDATE button is clicked it updates whole data in the sheet. but i need to only add new record when new sheet is added and not to rewrite the whole data again in summary sheet. Kindly help
2. The "Batch" column is linked with each sheet to go directly to that particular sheet when clicked. It does not work for all the sheets ( last 02 sheets it does not work, while code is the same).

Regards,
Hey mfaisal.ce,
Thank you for your question. You can use the following code instead of the code you used. Here, I have made some small changes to your code.

Code:
Sub Update_Record()
'Procedure to Consolidate all sheets in a workbook
On Error GoTo IfError
'1. Variables declaration
Dim Sht As Worksheet, DstSht As Worksheet
Dim DstRow As Long, v As Integer

'2. Disable Screen Updating - stop screen flickering
' And Disable Events to avoid inturupted dialogs / popups

With Application
.ScreenUpdating = False
.EnableEvents = False
End With

Set DstSht = Worksheets("Summary")
DstRow = 3

'5. Loop through each WorkSheet in the workbook and copy the data to the 'Consolidate_Data' WorkSheet

For Each Sht In ActiveWorkbook.Worksheets
If Sht.Name <> DstSht.Name Then
'5.1: Find the last row on the 'Consolidate_Data' sheet
DstRow = DstRow + 1
If Sht.Range("B5").Value = DstSht.Range("B" & DstRow).Value Then
GoTo txt
End If

Sht.Range("B5").Copy
DstSht.Range("B" & DstRow).PasteSpecial Paste:=xlPasteValues

Sht.Range("D3").Copy
DstSht.Range("C" & DstRow).PasteSpecial Paste:=xlPasteValues

Sht.Range("G3").Copy
DstSht.Range("D" & DstRow).PasteSpecial Paste:=xlPasteValues

Sht.Range("F5").Copy
DstSht.Range("E" & DstRow).PasteSpecial Paste:=xlPasteValues

Sht.Range("F6").Copy
DstSht.Range("F" & DstRow).PasteSpecial Paste:=xlPasteValues

Sht.Range("F7").Copy
DstSht.Range("G" & DstRow).PasteSpecial Paste:=xlPasteValues

Sht.Range("F8").Copy
DstSht.Range("H" & DstRow).PasteSpecial Paste:=xlPasteValues

ActiveSheet.Hyperlinks.Add Anchor:=DstSht.Range("C" & DstRow), Address:="", SubAddress:="'" & Sht.Name & "'" & "!A1"

End If

txt:
Next Sht

IfError:
'6. Enable Screen Updating and Events
With Application
.ScreenUpdating = True
.EnableEvents = True
End With

End Sub

Firstly, I have deleted the ClearContents method to stop deleting existing data from the summary sheet. Then, I used an If Statement to check if the cell contains the same data. If it contains the same data then it will go to the next sheet. You will have to add the new sheet at the end of all the existing sheets in your excel workbook and you will get your desired output.

1.png

Secondly, I changed the subaddress in the Hyperlinks.Add method.

2.png

I hope this will solve your problem. I have also added the Excel file here. Please let us know if you face any issues.

Regards
Mashhura Jahan
 

Attachments

Hey mfaisal.ce,
Thank you for your question. You can use the following code instead of the code you used. Here, I have made some small changes to your code.

Code:
Sub Update_Record()
'Procedure to Consolidate all sheets in a workbook
On Error GoTo IfError
'1. Variables declaration
Dim Sht As Worksheet, DstSht As Worksheet
Dim DstRow As Long, v As Integer

'2. Disable Screen Updating - stop screen flickering
' And Disable Events to avoid inturupted dialogs / popups

With Application
.ScreenUpdating = False
.EnableEvents = False
End With

Set DstSht = Worksheets("Summary")
DstRow = 3

'5. Loop through each WorkSheet in the workbook and copy the data to the 'Consolidate_Data' WorkSheet

For Each Sht In ActiveWorkbook.Worksheets
If Sht.Name <> DstSht.Name Then
'5.1: Find the last row on the 'Consolidate_Data' sheet
DstRow = DstRow + 1
If Sht.Range("B5").Value = DstSht.Range("B" & DstRow).Value Then
GoTo txt
End If

Sht.Range("B5").Copy
DstSht.Range("B" & DstRow).PasteSpecial Paste:=xlPasteValues

Sht.Range("D3").Copy
DstSht.Range("C" & DstRow).PasteSpecial Paste:=xlPasteValues

Sht.Range("G3").Copy
DstSht.Range("D" & DstRow).PasteSpecial Paste:=xlPasteValues

Sht.Range("F5").Copy
DstSht.Range("E" & DstRow).PasteSpecial Paste:=xlPasteValues

Sht.Range("F6").Copy
DstSht.Range("F" & DstRow).PasteSpecial Paste:=xlPasteValues

Sht.Range("F7").Copy
DstSht.Range("G" & DstRow).PasteSpecial Paste:=xlPasteValues

Sht.Range("F8").Copy
DstSht.Range("H" & DstRow).PasteSpecial Paste:=xlPasteValues

ActiveSheet.Hyperlinks.Add Anchor:=DstSht.Range("C" & DstRow), Address:="", SubAddress:="'" & Sht.Name & "'" & "!A1"

End If

txt:
Next Sht

IfError:
'6. Enable Screen Updating and Events
With Application
.ScreenUpdating = True
.EnableEvents = True
End With

End Sub

Firstly, I have deleted the ClearContents method to stop deleting existing data from the summary sheet. Then, I used an If Statement to check if the cell contains the same data. If it contains the same data then it will go to the next sheet. You will have to add the new sheet at the end of all the existing sheets in your excel workbook and you will get your desired output.

View attachment 55

Secondly, I changed the subaddress in the Hyperlinks.Add method.

View attachment 56

I hope this will solve your problem. I have also added the Excel file here. Please let us know if you face any issues.

Regards
Mashhura Jahan
Thanks a lot. It helped and solved my issue. is it possible to make a progress bar while refreshing/updating the records?

Regards,
 
Last edited:
Thanks a lot. It helped and solved my issue. is it possible to make a progress bar while refreshing/updating the records?

Regards,
Hello mfaisal.ce,
Thank you for your feedback. Showing a progress bar while refreshing/updating the records is possible.

Firstly, open the Visual Basic Editor >> select Insert tab >> select UserForm.

1.png

Then, change the Caption, Height, and Width of the UserForm according to your preference from the Properties window. The Properties window is located on the left side of the screen.

2.png

After that, select Label from the Toolbox >> click and drag your mouse cursor where you want to place the label. Then, change the Caption, Height, and Width of Label1 according to your preference from the Properties window.

3.png

Afterward, insert a Frame in the same way. Keep the Caption blank for Frame1. And, change the Height, and Width according to your preference from the Properties window.

Next, add another Label and place it on the frame. Change the BackColor of the label. Here, I kept it Highlight. And, left the Caption blank for Label2.

7.png

At this point, the UserForm will look like the following image. Right-click on the UserForm >> select View Code.

10.png

Then, write the following code in UserForm1.

Code:
Private Sub UserForm_Activate()
Call Update_Record
End Sub

Here, Update_Record is the sub procedure you used for updating the records. Now, write the following code instead of the code you used before.

Code:
Sub Update_Record()
'Procedure to Consolidate all sheets in a workbook
On Error GoTo IfError
'1. Variables declaration
Dim Sht As Worksheet, DstSht As Worksheet
Dim DstRow As Long, v As Integer
Dim prog_compl As Single

'2. Disable Screen Updating - stop screen flickering
' And Disable Events to avoid inturupted dialogs / popups
With Application
.ScreenUpdating = False
.EnableEvents = False
End With

Set DstSht = Worksheets("Summary")
DstRow = 3
i = 1

'5. Loop through each WorkSheet in the workbook and copy the data to the 'Consolidate_Data' WorkSheet
For Each Sht In ActiveWorkbook.Worksheets

If Sht.Name <> DstSht.Name Then
'5.1: Find the last row on the 'Consolidate_Data' sheet
DstRow = DstRow + 1
If Sht.Range("B5").Value = DstSht.Range("B" & DstRow).Value Then
GoTo txt
End If

Sht.Range("B5").Copy
DstSht.Range("B" & DstRow).PasteSpecial Paste:=xlPasteValues

Sht.Range("D3").Copy
DstSht.Range("C" & DstRow).PasteSpecial Paste:=xlPasteValues

Sht.Range("G3").Copy
DstSht.Range("D" & DstRow).PasteSpecial Paste:=xlPasteValues

Sht.Range("F5").Copy
DstSht.Range("E" & DstRow).PasteSpecial Paste:=xlPasteValues

Sht.Range("F6").Copy
DstSht.Range("F" & DstRow).PasteSpecial Paste:=xlPasteValues

Sht.Range("F7").Copy
DstSht.Range("G" & DstRow).PasteSpecial Paste:=xlPasteValues

Sht.Range("F8").Copy
DstSht.Range("H" & DstRow).PasteSpecial Paste:=xlPasteValues

ActiveSheet.Hyperlinks.Add Anchor:=DstSht.Range("C" & DstRow), Address:="", SubAddress:="'" & Sht.Name & "'" & "!A1"
End If

txt:
prog_compl = (i / ThisWorkbook.Sheets.Count) * 100
progress_bar prog_compl
i = i + 1

Next Sht

IfError:
'6. Enable Screen Updating and Events
With Application
.ScreenUpdating = True
.EnableEvents = True
End With

Unload UserForm1
End Sub

Sub progress_bar(prog_compl As Single)
UserForm1.Label1.Caption = prog_compl & "% Completed"
UserForm1.Label2.Width = prog_compl * 2
DoEvents
End Sub

Here, I have modified the code a little bit. I have added the marked portions you can see in the following image.

12.png

Now, open another module >> write the following code.

Code:
Sub show_userform()
UserForm1.Show
End Sub

After that, assign the macro named show_userform to your CommandButton.
Finally, you will be able to see the progress bar whenever you click on the Update button. You can close the progress bar manually by pressing the cross button when it says “100% Completed”.

16.png

If you want to close the progress bar automatically once the whole record is updated then you can add the following line in the code.

17.png

I hope this will solve your problem. I have also attached the excel file for your convenience. Please let us know if you face any other problems.

Regards
Mashhura jahan
 

Attachments

  • 7.png
    7.png
    12.2 KB · Views: 3
  • R-301.xlsm
    R-301.xlsm
    295.6 KB · Views: 7

Online statistics

Members online
0
Guests online
4
Total visitors
4

Forum statistics

Threads
371
Messages
1,627
Members
705
Latest member
curioso
Back
Top