VBA code snippet to consolidate/Sum

F3hunter

New Member
Joined
Jan 17, 2015
Messages
18
Hi,

I am your average Excel user having a hard time trying an end result that will work for me. Horrid VBA skills here. I have tried Pivot Tables (Too busy), I ave tried SUMIFS as well to no avail.

If someone could help that would be awesome. I am looking for code to do the following,
Consolidate the redundant items in Product column A, sum the values from those in columns Pounds D and Total F. All this and keep the consolidation/SUM to each specific category.

Each product item can be in a different "Category" which is what is giving me a headache trying to figure this out.

What it looks like before consolidation:

[TABLE="width: 453"]
<tbody>[TR]
[TD]Product Code[/TD]
[TD]Description[/TD]
[TD]Category[/TD]
[TD]Pounds[/TD]
[TD]Price[/TD]
[TD]Total[/TD]
[/TR]
[TR]
[TD]1111[/TD]
[TD]SC[/TD]
[TD]12NBCBER[/TD]
[TD]40.00[/TD]
[TD]$3.40[/TD]
[TD]$136.00[/TD]
[/TR]
[TR]
[TD]1111[/TD]
[TD]SC[/TD]
[TD]12NBCBER[/TD]
[TD]20.00[/TD]
[TD]$3.40[/TD]
[TD]$68.00[/TD]
[/TR]
[TR]
[TD]1111[/TD]
[TD]SC[/TD]
[TD]12NBCBER[/TD]
[TD]40.00[/TD]
[TD]$3.40[/TD]
[TD]$136.00[/TD]
[/TR]
[TR]
[TD]1111[/TD]
[TD]SC[/TD]
[TD]12NBCBER[/TD]
[TD]100.00[/TD]
[TD]$3.40[/TD]
[TD]$340.00[/TD]
[/TR]
[TR]
[TD]1111[/TD]
[TD]SC[/TD]
[TD]12NBCBER[/TD]
[TD]20.00[/TD]
[TD]$3.40[/TD]
[TD]$68.00[/TD]
[/TR]
[TR]
[TD]1112[/TD]
[TD]NLR[/TD]
[TD]12NBCBER[/TD]
[TD]20.00[/TD]
[TD]$6.22[/TD]
[TD]$124.40[/TD]
[/TR]
[TR]
[TD]1112[/TD]
[TD]NLR[/TD]
[TD]12NBCBER[/TD]
[TD]20.00[/TD]
[TD]$6.22[/TD]
[TD]$124.40[/TD]
[/TR]
[TR]
[TD]1113[/TD]
[TD]Wh[/TD]
[TD]12NBCBER[/TD]
[TD]300.00[/TD]
[TD]$2.95[/TD]
[TD]$885.00[/TD]
[/TR]
[TR]
[TD]1113[/TD]
[TD]Wh[/TD]
[TD]12NBCBER[/TD]
[TD]200.00[/TD]
[TD]$2.95[/TD]
[TD]$590.00[/TD]
[/TR]
[TR]
[TD]1113[/TD]
[TD]Wh[/TD]
[TD]12NBCBER[/TD]
[TD]200.00[/TD]
[TD]$2.95[/TD]
[TD]$590.00[/TD]
[/TR]
[TR]
[TD]1113[/TD]
[TD]Wh[/TD]
[TD]12NBCBER[/TD]
[TD]700.00[/TD]
[TD]$2.95[/TD]
[TD]$2065.00[/TD]
[/TR]
[TR]
[TD]1114[/TD]
[TD]Bl1[/TD]
[TD]12NBCBER[/TD]
[TD]60.00[/TD]
[TD]$10.18[/TD]
[TD]$610.80[/TD]
[/TR]
[TR]
[TD]1114[/TD]
[TD]Bl1[/TD]
[TD]12NBCBER[/TD]
[TD]100.00[/TD]
[TD]$10.18[/TD]
[TD]$1018.00[/TD]
[/TR]
[TR]
[TD]1114[/TD]
[TD]Bl1[/TD]
[TD]12NBCBER[/TD]
[TD]340.00[/TD]
[TD]$10.18[/TD]
[TD]$3461.20[/TD]
[/TR]
[TR]
[TD]1115[/TD]
[TD]Bl2[/TD]
[TD]12NBCBER[/TD]
[TD]80.00[/TD]
[TD]$10.18[/TD]
[TD]$814.40[/TD]
[/TR]
[TR]
[TD]1115[/TD]
[TD]Bl2[/TD]
[TD]12NBCBER[/TD]
[TD]80.00[/TD]
[TD]$10.18[/TD]
[TD]$814.40[/TD]
[/TR]
[TR]
[TD]1115[/TD]
[TD]Bl2[/TD]
[TD]12NBCBER[/TD]
[TD]300.00[/TD]
[TD]$10.18[/TD]
[TD]$3054.00[/TD]
[/TR]
[TR]
[TD]1115[/TD]
[TD]Bl2[/TD]
[TD]12NBCBER[/TD]
[TD]40.00[/TD]
[TD]$10.18[/TD]
[TD]$407.20[/TD]
[/TR]
[TR]
[TD]1116[/TD]
[TD]2935[/TD]
[TD]12NBCBER[/TD]
[TD]20.00[/TD]
[TD]$13.50[/TD]
[TD]$270.00[/TD]
[/TR]
[TR]
[TD]1117[/TD]
[TD]G[/TD]
[TD]12NBCBER[/TD]
[TD]91.00[/TD]
[TD]$5.68[/TD]
[TD]$516.88[/TD]
[/TR]
[TR]
[TD]1117[/TD]
[TD]G[/TD]
[TD]12NBCBER[/TD]
[TD]40.00[/TD]
[TD]$5.68[/TD]
[TD]$227.20[/TD]
[/TR]
[TR]
[TD]1117[/TD]
[TD]G[/TD]
[TD]12NBCBER[/TD]
[TD]40.00[/TD]
[TD]$5.68[/TD]
[TD]$227.20[/TD]
[/TR]
[TR]
[TD]1117[/TD]
[TD]G[/TD]
[TD]12NBCBER[/TD]
[TD]100.00[/TD]
[TD]$5.68[/TD]
[TD]$568.00[/TD]
[/TR]
[TR]
[TD]1118[/TD]
[TD]Mod Bl[/TD]
[TD]12NBCBER[/TD]
[TD]60.00[/TD]
[TD]$9.67[/TD]
[TD]$580.20[/TD]
[/TR]
[TR]
[TD]1118[/TD]
[TD]Mod Bl[/TD]
[TD]12NBCBER[/TD]
[TD]40.00[/TD]
[TD]$9.67[/TD]
[TD]$386.80[/TD]
[/TR]
[TR]
[TD]1118[/TD]
[TD]Mod Bl[/TD]
[TD]12NBCBER[/TD]
[TD]40.00[/TD]
[TD]$9.67[/TD]
[TD]$386.80[/TD]
[/TR]
[TR]
[TD]1118[/TD]
[TD]Mod Bl[/TD]
[TD]12NBCBER[/TD]
[TD]120.00[/TD]
[TD]$9.67[/TD]
[TD]$1160.40[/TD]
[/TR]
[TR]
[TD]1119[/TD]
[TD]CY[/TD]
[TD]12NBCSD[/TD]
[TD]20.00[/TD]
[TD]$6.52[/TD]
[TD]$130.40[/TD]
[/TR]
[TR]
[TD]1119[/TD]
[TD]CY[/TD]
[TD]12NBCSD[/TD]
[TD]60.00[/TD]
[TD]$6.52[/TD]
[TD]$391.20[/TD]
[/TR]
[TR]
[TD]1111[/TD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/TD]
[TD]12NBCSD[/TD]
[TD]40.00[/TD]
[TD]$9.67[/TD]
[TD]$386.80[/TD]
[/TR]
[TR]
[TD]1131[/TD]
[TD]Pb[/TD]
[TD]12NBCSD[/TD]
[TD]60.00[/TD]
[TD]$9.67[/TD]
[TD]$580.20[/TD]
[/TR]
[TR]
[TD]1132[/TD]
[TD]MRR[/TD]
[TD]12NBCSD[/TD]
[TD]20.00[/TD]
[TD]$6.70[/TD]
[TD]$134.00[/TD]
[/TR]
[TR]
[TD]1133[/TD]
[TD]220[/TD]
[TD]12NBCSD[/TD]
[TD]80.00[/TD]
[TD]$6.70[/TD]
[TD]$536.00[/TD]
[/TR]
[TR]
[TD]1134[/TD]
[TD]PBB[/TD]
[TD]12NBCSD[/TD]
[TD]260.00[/TD]
[TD]$10.89[/TD]
[TD]$2831.40[/TD]
[/TR]
[TR]
[TD]1134[/TD]
[TD]PBB[/TD]
[TD]12NBCSD[/TD]
[TD]140.00[/TD]
[TD]$10.89[/TD]
[TD]$1524.60[/TD]
[/TR]
[TR]
[TD]1134[/TD]
[TD]PBB[/TD]
[TD]12NBCSD[/TD]
[TD]300.00[/TD]
[TD]$10.89[/TD]
[TD]$3267.00[/TD]
[/TR]
[TR]
[TD]1111[/TD]
[TD]SC[/TD]
[TD]16NBCBER[/TD]
[TD]20.00[/TD]
[TD]$3.40[/TD]
[TD]$68.00[/TD]
[/TR]
[TR]
[TD]1114[/TD]
[TD]Bl1[/TD]
[TD]16NBCBER[/TD]
[TD]60.00[/TD]
[TD]$10.18[/TD]
[TD]$610.80[/TD]
[/TR]
[TR]
[TD]1115[/TD]
[TD]Bl2[/TD]
[TD]16NBCBER[/TD]
[TD]80.00[/TD]
[TD]$10.18[/TD]
[TD]$814.40[/TD]
[/TR]
[TR]
[TD]1135[/TD]
[TD]MLG[/TD]
[TD]16NBCSD[/TD]
[TD]10.00[/TD]
[TD]$7.61[/TD]
[TD]$76.10[/TD]
[/TR]
[TR]
[TD]1121[/TD]
[TD]BW[/TD]
[TD]16NBCSD[/TD]
[TD]25.00[/TD]
[TD]$3.97[/TD]
[TD]$99.25[/TD]
[/TR]
[TR]
[TD]1125[/TD]
[TD]DB[/TD]
[TD]16NBCSD[/TD]
[TD]60.00[/TD]
[TD]$9.15[/TD]
[TD]$549.00[/TD]
[/TR]
[TR]
[TD]1135[/TD]
[TD]pp[/TD]
[TD]12BCBER[/TD]
[TD]20.00[/TD]
[TD]$7.65[/TD]
[TD]$153.00[/TD]
[/TR]
</tbody>[/TABLE]

What I need it to like like after:

[TABLE="width: 453"]
<tbody>[TR]
[TD]Product Code[/TD]
[TD]Description[/TD]
[TD]Category[/TD]
[TD]Pounds[/TD]
[TD]Price[/TD]
[TD]Total[/TD]
[/TR]
[TR]
[TD]1111[/TD]
[TD]SC[/TD]
[TD]12NBCBER[/TD]
[TD]220.00[/TD]
[TD]$ 3.40[/TD]
[TD]$748.00[/TD]
[/TR]
[TR]
[TD]1112[/TD]
[TD]NLR[/TD]
[TD]12NBCBER[/TD]
[TD]40.00[/TD]
[TD]$ 6.22[/TD]
[TD]$248.80[/TD]
[/TR]
[TR]
[TD]1113[/TD]
[TD]Wh[/TD]
[TD]12NBCBER[/TD]
[TD]1400.00[/TD]
[TD]$ 2.95[/TD]
[TD]$4130.00[/TD]
[/TR]
[TR]
[TD]1135[/TD]
[TD]pp[/TD]
[TD]12BCBER[/TD]
[TD]20.00[/TD]
[TD]$ 7.65[/TD]
[TD]$153.00[/TD]
[/TR]
[TR]
[TD]1119[/TD]
[TD]CY[/TD]
[TD]12NBCSD[/TD]
[TD]80.00[/TD]
[TD]$ 6.52[/TD]
[TD]$521.60[/TD]
[/TR]
[TR]
[TD]1113[/TD]
[TD]Wh[/TD]
[TD]12NBCSD[/TD]
[TD]275.00[/TD]
[TD]$ 2.95[/TD]
[TD]$811.25[/TD]
[/TR]
</tbody>[/TABLE]

Thanks in advance for any help you can offer.
 

Excel Facts

Did you know Excel offers Filter by Selection?
Add the AutoFilter icon to the Quick Access Toolbar. Select a cell containing Apple, click AutoFilter, and you will get all rows with Apple
After scouring the internet I located several snippets and have tried to break them down to understand them. I have put this code together and it partially works, but does not seem to be grabbing all the data in column A and is not summing the duplicate data.



Here is the code that I have sewn together:

Private Sub CommandButton21_Click()


Set wsCopy = Sheets("Sheet1")
Set wsPaste = Sheets("Sheet2")
lBR = wsCopy.Cells(Application.Rows.Count, "A").End(xlUp).Row
Set rCopy = wsCopy.Range("A1:F" & lBR)
Set rPaste = wsPaste.Range("A1:F" & lBR)
rCopy.Copy rPaste
rPaste.RemoveDuplicates Columns:=Array(1), Header _
:=xlYes
wsPaste.Range("D:D").Formula = "=SUMIFS(Sheet1!D:D,Sheet1!A:A,Sheet1!C:C,Sheet2!C:C)"
wsPaste.Range("F:F").Formula = "=SUMIFS(Sheet1!F:F,Sheet1!A:A,Sheet1!C:C,Sheet2!C:C)"
lBR = wsPaste.Cells(Application.Rows.Count, "A").End(xlUp).Row


Set rPaste = wsPaste.Range("A1:F" & lBR)
rPaste.Copy
rPaste.PasteSpecial xlPasteValues




End Sub
 
Last edited:
Upvote 0
F3hunter,

Welcome to the MrExcel forum.

1. What version of Excel and Windows are you using?

2. Are you using a PC or a Mac?


Sample raw data in worksheet Sheet1 (the worksheet name can be changed in the macro):


Excel 2007
ABCDEF
1Product CodeDescriptionCategoryPoundsPriceTotal
21111SC12NBCBER40$3.40$136.00
31111SC12NBCBER20$3.40$68.00
41111SC12NBCBER40$3.40$136.00
51111SC12NBCBER100$3.40$340.00
61111SC12NBCBER20$3.40$68.00
71112NLR12NBCBER20$6.22$124.40
81112NLR12NBCBER20$6.22$124.40
91113Wh12NBCBER300$2.95$885.00
101113Wh12NBCBER200$2.95$590.00
111113Wh12NBCBER200$2.95$590.00
121113Wh12NBCBER700$2.95$2,065.00
131114Bl112NBCBER60$10.18$610.80
141114Bl112NBCBER100$10.18$1,018.00
151114Bl112NBCBER340$10.18$3,461.20
161115Bl212NBCBER80$10.18$814.40
171115Bl212NBCBER80$10.18$814.40
181115Bl212NBCBER300$10.18$3,054.00
191115Bl212NBCBER40$10.18$407.20
201116293512NBCBER20$13.50$270.00
211117G12NBCBER91$5.68$516.88
221117G12NBCBER40$5.68$227.20
231117G12NBCBER40$5.68$227.20
241117G12NBCBER100$5.68$568.00
251118Mod Bl12NBCBER60$9.67$580.20
261118Mod Bl12NBCBER40$9.67$386.80
271118Mod Bl12NBCBER40$9.67$386.80
281118Mod Bl12NBCBER120$9.67$1,160.40
291119CY12NBCSD20$6.52$130.40
301119CY12NBCSD60$6.52$391.20
311111SC12NBCSD40$3.40$136.00
321113Wh12NBCSD50$2.95$147.50
331113Wh12NBCSD25$2.95$73.75
341113Wh12NBCSD50$2.95$147.50
351113Wh12NBCSD150$2.95$442.50
361120RBB12NBCSD20$6.17$123.40
371121BW12NBCSD25$3.97$99.25
381122Br12NBCSD160$13.50$2,160.00
391123RB12NBCSD40$6.17$246.80
401124DG12NBCSD17$13.45$228.65
411125DB12NBCSD20$9.15$183.00
421125DB12NBCSD40$9.15$366.00
431125DB12NBCSD20$9.15$183.00
441125DB12NBCSD20$9.15$183.00
451126Grove12NBCSD17$6.70$113.90
461127Hc12NBCSD10$6.17$61.70
471128Ha12NBCSD40$7.61$304.40
481129Fr12NBCSD10$13.45$134.50
491130Pr12NBCSD20$6.38$127.60
501130Pr12NBCSD20$6.38$127.60
511130Pr12NBCSD40$6.38$255.20
521131Pb12NBCSD20$9.67$193.40
531131Pb12NBCSD40$9.67$386.80
541131Pb12NBCSD60$9.67$580.20
551132MRR12NBCSD20$6.70$134.00
56113322012NBCSD80$6.70$536.00
571134PBB12NBCSD260$10.89$2,831.40
581134PBB12NBCSD140$10.89$1,524.60
591134PBB12NBCSD300$10.89$3,267.00
601111SC16NBCBER20$3.40$68.00
611114Bl116NBCBER60$10.18$610.80
621115Bl216NBCBER80$10.18$814.40
631135MLG16NBCSD10$7.61$76.10
641121BW16NBCSD25$3.97$99.25
651125DB16NBCSD60$9.15$549.00
661135pp12BCBER20$7.65$153.00
67
Sheet1


After the macro:


Excel 2007
IJKLMN
1Product CodeDescriptionCategoryPoundsPriceTotal
21111SC12NBCBER220$3.40$748.00
31111SC12NBCSD40$3.40$136.00
41111SC16NBCBER20$3.40$68.00
51112NLR12NBCBER40$6.22$248.80
61113Wh12NBCBER1400$2.95$4,130.00
71113Wh12NBCSD275$2.95$811.25
81114Bl112NBCBER500$10.18$5,090.00
91114Bl116NBCBER60$10.18$610.80
101115Bl212NBCBER500$10.18$5,090.00
111115Bl216NBCBER80$10.18$814.40
121116293512NBCBER20$13.50$270.00
131117G12NBCBER271$5.68$1,539.28
141118Mod Bl12NBCBER260$9.67$2,514.20
151119CY12NBCSD80$6.52$521.60
161120RBB12NBCSD20$6.17$123.40
171121BW12NBCSD25$3.97$99.25
181121BW16NBCSD25$3.97$99.25
191122Br12NBCSD160$13.50$2,160.00
201123RB12NBCSD40$6.17$246.80
211124DG12NBCSD17$13.45$228.65
221125DB12NBCSD100$9.15$915.00
231125DB16NBCSD60$9.15$549.00
241126Grove12NBCSD17$6.70$113.90
251127Hc12NBCSD10$6.17$61.70
261128Ha12NBCSD40$7.61$304.40
271129Fr12NBCSD10$13.45$134.50
281130Pr12NBCSD80$6.38$510.40
291131Pb12NBCSD120$9.67$1,160.40
301132MRR12NBCSD20$6.70$134.00
31113322012NBCSD80$6.70$536.00
321134PBB12NBCSD700$10.89$7,623.00
331135MLG16NBCSD10$7.61$76.10
341135pp12BCBER20$7.65$153.00
35
Sheet1


Please TEST this FIRST in a COPY of your workbook (always make a backup copy before trying new code, you never know what you might lose).

1. Copy the below code
2. Open your NEW workbook
3. Press the keys ALT + F11 to open the Visual Basic Editor
4. Press the keys ALT + I to activate the Insert menu
5. Press M to insert a Standard Module
6. Where the cursor is flashing, paste the code
7. Press the keys ALT + Q to exit the Editor, and return to Excel
8. To run the macro from Excel press ALT + F8 to display the Run Macro Dialog. Double Click the macro's name to Run it.

Code:
Sub ConsolidateData()
' hiker95, 01/17/2015, ME829707
Dim oa As Variant
Dim lr As Long, r As Long, nr As Long, n As Long
Application.ScreenUpdating = False
With Sheets("Sheet1")
  .Columns("I:N").ClearContents
  .Cells(1, 9).Resize(, 6).Value = .Cells(1, 1).Resize(, 6).Value
  lr = .Cells(Rows.Count, 1).End(xlUp).Row
  oa = .Range("A2:F" & lr)
  With .Range("G2:G" & lr)
    .Formula = "=A2&B2&C2"
    .Value = .Value
  End With
  .Range("A2:G" & lr).Sort key1:=.Range("G2"), order1:=1
  nr = 1
  For r = 2 To lr
    n = Application.CountIf(.Columns(7), .Cells(r, 7).Value)
    nr = nr + 1
    If n = 1 Then
      .Cells(nr, 9).Resize(, 6).Value = .Cells(r, 1).Resize(, 6).Value
    Else
      .Cells(nr, 9).Resize(, 3).Value = .Cells(r, 1).Resize(, 3).Value
      .Cells(nr, 12).Value = Evaluate("=Sum(D" & r & ":D" & r + n - 1 & ")")
      .Cells(nr, 13).Value = .Cells(r, 5).Value
      .Cells(nr, 14).Value = Evaluate("=Sum(F" & r & ":F" & r + n - 1 & ")")
    End If
    r = r + n - 1
  Next r
  .Range("M2:M" & nr).NumberFormat = "$#,##0.00_);[Red]($#,##0.00)"
  .Range("N2:N" & nr).NumberFormat = "$#,##0.00_);[Red]($#,##0.00)"
  .Range("A2:F" & lr) = oa
  .Range("G2:G" & lr).ClearContents
  .Columns("I:N").AutoFit
End With
Application.ScreenUpdating = True
End Sub

Before you use the macro with Excel 2007 or newer, save your workbook, Save As, a macro enabled workbook with the file extension .xlsm

Then run the ConsolidateData macro.
 
Upvote 0
Hiker95-Wow..Worked perfectly, I've spent days on this and must extend my sincerest gratitude. I'll study that code to get a better understanding of how it works so when the next project comes I will be better prepared. Have a great weekend!

Windows 8.1
Excel 2010

F3
 
Upvote 0
F3hunter,

Thanks for the feedback.

You are very welcome. Glad I could help.

And, come back anytime.


I missed your posted macro - you are using two worksheets.


Please TEST this FIRST in a COPY of your workbook (always make a backup copy before trying new code, you never know what you might lose).

Code:
Sub ConsolidateData_V2()
' hiker95, 01/17/2015, ME829707
Dim w1 As Worksheet, w2 As Worksheet
Dim oa As Variant
Dim lr As Long, r As Long, nr As Long, n As Long
Application.ScreenUpdating = False
Set w1 = Sheets("Sheet1")
Set w2 = Sheets("Sheet2")
With w2
  .UsedRange.ClearContents
  .Range("A1").Resize(, 6).Value = w1.Range("A1").Resize(, 6).Value
End With
With w1
  lr = .Cells(Rows.Count, 1).End(xlUp).Row
  oa = .Range("A2:F" & lr)
  With .Range("G2:G" & lr)
    .Formula = "=A2&B2&C2"
    .Value = .Value
  End With
  .Range("A2:G" & lr).Sort key1:=.Range("G2"), order1:=1
  nr = 1
  For r = 2 To lr
    n = Application.CountIf(.Columns(7), .Cells(r, 7).Value)
    nr = nr + 1
    If n = 1 Then
      w2.Cells(nr, 1).Resize(, 6).Value = w1.Cells(r, 1).Resize(, 6).Value
    Else
      w2.Cells(nr, 1).Resize(, 3).Value = w1.Cells(r, 1).Resize(, 3).Value
      w2.Cells(nr, 4).Value = Evaluate("=Sum(D" & r & ":D" & r + n - 1 & ")")
      w2.Cells(nr, 5).Value = w1.Cells(r, 5).Value
      w2.Cells(nr, 6).Value = Evaluate("=Sum(F" & r & ":F" & r + n - 1 & ")")
    End If
    r = r + n - 1
  Next r
  w2.Range("E2:E" & nr).NumberFormat = "$#,##0.00_);[Red]($#,##0.00)"
  w2.Range("F2:F" & nr).NumberFormat = "$#,##0.00_);[Red]($#,##0.00)"
  .Range("A2:F" & lr) = oa
  .Range("G2:G" & lr).ClearContents
  w2.Columns("A:F").AutoFit
End With
w2.Activate
Application.ScreenUpdating = True
End Sub

Before you use the macro with Excel 2007 or newer, save your workbook, Save As, a macro enabled workbook with the file extension .xlsm

Then run the ConsolidateData_V2 macro.
 
Upvote 0
Yes, I was using 2 worksheets and thank you for noticing that and spending the time to change it up. Again, it worked perfectly!

My wife is happy as well! Spend a little time with her this weekend now.:eeek:
 
Upvote 0
F3hunter,

Thanks for the feedback.

You are very welcome. Glad I could help.

And, come back anytime.
 
Upvote 0

Similar threads

Forum statistics

Threads
1,223,236
Messages
6,170,915
Members
452,366
Latest member
TePunaBloke

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top