Improve speed of a recorded macro

mkseto

New Member
Joined
Aug 14, 2018
Messages
38
I've only started to learn macro.
I need to work on a spreadsheet everyday (different number of rows) to basically do the following:
1) In worksheet "Combined", find the total amount of "deposits" for each account (column "J") and also total number of items on deposit (column "M").
2) Copy the results from above to another worksheet "Results" with the same headings.

With no knowledge with VBA, I managed to record a macro that works, but very slow because I have to assume a maximum of 20,000 rows of data, so I had to copy everything down the 20,000 rows and calculations are done for 20,000 rows.

Below is the recorded macro, any suggestion that can make this run faster would be much appreciated (the last few lines are VBA codes I found via Google and added to my reocrded codes):
Code:
Sub Convert()
'
' Convert Macro
'


'
    Sheets("Combined").Select
    Rows("1:2").Select
    Selection.Delete Shift:=xlUp
    Columns("J:J").Select
    Selection.Replace What:="~*", Replacement:="#", LookAt:=xlPart, _
        SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
        ReplaceFormat:=False
    Selection.Replace What:="~?", Replacement:="/", LookAt:=xlPart, _
        SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
        ReplaceFormat:=False
    Range("N2").Select
    ActiveCell.FormulaR1C1 = "=RC[-10]&"",""&RC[-5]&"",""&RC[-4]"
    Range("N2").Select
    Selection.Copy
    Range("N20001").Select
    Range("N3:N20001").Select
    Range("N20001").Activate
    ActiveSheet.Paste
    Application.CutCopyMode = False
    Columns("N:N").Select
    Range("N20001").Activate
    Selection.Copy
    Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
        :=False, Transpose:=False
    Application.CutCopyMode = False
    Range("N2:N20001").AdvancedFilter Action:=xlFilterCopy, CopyToRange:=Range( _
        "O2"), Unique:=True
    Range("P2").Select
    ActiveCell.FormulaR1C1 = "=SUMIF(C[-2],RC[-1],C[-4])"
    Range("Q2").Select
    ActiveCell.FormulaR1C1 = "=SUMIF(C[-3],RC[-2],C[-4])"
    Range("P2:Q2").Select
    Selection.Copy
    Range("P3").Select
    Range("P3:Q20001").Select
    ActiveSheet.Paste
    Application.CutCopyMode = False
    Columns("P:Q").Select
    Selection.Copy
    Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
        :=False, Transpose:=False
    Range("R2").Select
    Application.CutCopyMode = False
    ActiveCell.FormulaR1C1 = "=IF(RC[-2]>0,""True"",""False"")"
    Range("R2").Select
    Selection.Copy
    Range("R3").Select
    Range("R3:R20001").Select
    ActiveSheet.Paste
    Application.CutCopyMode = False
    Columns("R:R").Select
    Selection.Copy
    Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
        :=False, Transpose:=False
    Columns("J:J").Select
    Selection.Replace What:="/", Replacement:="?", LookAt:=xlPart, _
        SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
        ReplaceFormat:=False
    Selection.Replace What:="#", Replacement:="*", LookAt:=xlPart, _
        SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
        ReplaceFormat:=False
    Range("R2").Select
    Application.CutCopyMode = False
    Columns("P:P").Select
    Selection.NumberFormat = "#,##0.00"
    Columns("Q:Q").Select
    Selection.NumberFormat = "#,##0"
    Range("R2").Select
        Dim c As Range
    Dim j As Integer
    Dim Source As Worksheet
    Dim Target As Worksheet
    Set Source = ActiveWorkbook.Worksheets("Combined")
    Set Target = ActiveWorkbook.Worksheets("Results")
    j = 2     ' Start copying to row 2 in target sheet
    For Each c In Source.Range("R3:R20001") 
        If c = "True" Then
           Source.Rows(c.Row).Copy Target.Rows(j)
           j = j + 1
        End If
    Next c
    Sheets("Convert").Select
    Range("C3").Select
End Sub
 
Last edited by a moderator:

Excel Facts

What does custom number format of ;;; mean?
Three semi-colons will hide the value in the cell. Although most people use white font instead.
Welcome to the Board!

There are a number of things you can do to increase speed, such as:
1. Eliminate a lot of "Select" and "Activate" statements. Most times when you have one line end with "Select" or "Activate" and the next line begins with "Selection" or "ActiveCell", you can combine the two lines together. It is usually not necessary to select the ranges to work with them, and doing so actually slows down the code.
2. You can often apply your formulas to an entire range all at once.
3. You can limit your loops to only run down as far as the bottom of the data (no need to "high-end it" with a large value).
4. You can suppress calculations and screen updating until the macro completes, which eliminates screen flickering and intermediate calculations, so your code should run faster.

Here is a first run at it, but we can still make more improvements.
Code:
Sub Convert()
'
' Convert Macro
'
'
    Dim c As Range
    Dim j As Integer
    Dim mySource As Worksheet
    Dim myTarget As Worksheet
    Set mySource = ActiveWorkbook.Worksheets("Combined")
    Set myTarget = ActiveWorkbook.Worksheets("Results")
    Dim lastRow As Long

    Application.ScreenUpdating = False
    Application.Calculation = xlCalculationManual

    Sheets("Combined").Select

    Rows("1:2").Delete Shift:=xlUp

    With Columns("J:J")
        .Replace What:="~*", Replacement:="#", LookAt:=xlPart, _
            SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
            ReplaceFormat:=False
        .Replace What:="~?", Replacement:="/", LookAt:=xlPart, _
            SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
            ReplaceFormat:=False
        .Replace What:="/", Replacement:="?", LookAt:=xlPart, _
            SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
            ReplaceFormat:=False
        .Replace What:="#", Replacement:="*", LookAt:=xlPart, _
            SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
            ReplaceFormat:=False
    End With

    Range("N3:N20001").FormulaR1C1 = "=RC[-10]&"",""&RC[-5]&"",""&RC[-4]"
    Range("N3:N20001").Value = Range("N3:N20001").Value

    Range("N2:N20001").AdvancedFilter Action:=xlFilterCopy, CopyToRange:=Range( _
        "O2"), Unique:=True

    Range("P2:P20001").FormulaR1C1 = "=SUMIF(C[-2],RC[-1],C[-4])"
    Range("Q2:Q20001").FormulaR1C1 = "=SUMIF(C[-3],RC[-2],C[-4])"
    Range("P2:Q20001").Value = Range("P2:Q20001").Value

    Range("R3:R20001").FormulaR1C1 = "=IF(RC[-2]>0,""True"",""False"")"
    Range("R3:R20001").Value = Range("R3:R20001").Value

    Columns("P:P").NumberFormat = "#,##0.00"
    Columns("Q:Q").NumberFormat = "#,##0"

    'Find last row with data in column R
    lastRow = Cells(Rows.Count, "R").End(xlUp).Row

    j = 2 ' Start copying to row 2 in target sheet
    For Each c In mySource.Range("R3:R" & lastRow)
        If c = "True" Then
            mySource.Rows(c.Row).Copy myTarget.Rows(j)
            j = j + 1
        End If
    Next c

    Sheets("Convert").Select
    Range("C3").Select
    
    Application.Calculation = xlCalculationAutomatic
    Application.ScreenUpdating = True
    
End Sub
Here are a few things we can still do, with more information.

Like I limited the loop at the bottom by finding the last line in column R with data, we can do the same above and replace all our row "20001" references. However, we would need you to tell us exactly which column we can look at to dynamically figure out what row is our last row of data (in other words, can you tell us which column will always have data in it for every row with data)?

Also, we can replace the Loop at the bottom of your code with a Filter. One way to is just copy all the data over, Filter on column R, and delete the hidden (or unhidden rows, depending on how you filtered). Loops are notoriously slow, so if we can eliminate them, it will also speed up your code. I would just want to know how many columns you have data in (is it columns A-R?), and if there is any header on the data, and if so, is it just row 2, or rows 1 and 2 together?
 
Upvote 0
Thank you for the quick reply.
Regarding your question, column "A" will always have data. The columns are from "A" to "M" for a total of 13 columns.
Below are some sample data (new to this board, couldn't figure out how to upload a file). I'm using "Curr" + "CR_RT" + "CR_ACCT" combination as an identifier. All row having the same identifier will have the "Amount" and "Items" field added up for the total, then the "Curr" + "CR_RT" + "CR_ACCT" fields will be copied over to the "Results" sheet along with the total "Amount" and Total "Items". I tried to run your code but somehow getting all "false" for the statement "=IF(RC[-2]>0,""True"",""False"" but I don't understand why.

[TABLE="width: 1018"]
<colgroup><col><col><col><col><col><col><col><col><col><col><col><col><col></colgroup><tbody>[TR]
[TD]Date[/TD]
[TD]Ctr[/TD]
[TD]Entry[/TD]
[TD]Curr[/TD]
[TD]Type[/TD]
[TD]ISN[/TD]
[TD]Unit Number[/TD]
[TD]SERIAL[/TD]
[TD]Cr_RT[/TD]
[TD]Cr_Acct[/TD]
[TD]Code[/TD]
[TD]AMOUNT[/TD]
[TD]Items[/TD]
[/TR]
[TR]
[TD]30-Jul-2018[/TD]
[TD]CAL[/TD]
[TD]5309[/TD]
[TD]CAD[/TD]
[TD]Regular[/TD]
[TD]3000902814[/TD]
[TD] [/TD]
[TD]000000694367[/TD]
[TD]00009-003[/TD]
[TD]124-171-0[/TD]
[TD]89[/TD]
[TD="align: right"]$5,238.25[/TD]
[TD="align: right"]7[/TD]
[/TR]
[TR]
[TD]30-Jul-2018[/TD]
[TD]CAL[/TD]
[TD]5309[/TD]
[TD]CAD[/TD]
[TD]Regular[/TD]
[TD]3000902822[/TD]
[TD] [/TD]
[TD]000001586165[/TD]
[TD]00009-003[/TD]
[TD]124-171-0[/TD]
[TD]89[/TD]
[TD="align: right"]$4,967.13[/TD]
[TD="align: right"]8[/TD]
[/TR]
[TR]
[TD]30-Jul-2018[/TD]
[TD]CAL[/TD]
[TD]5309[/TD]
[TD]CAD[/TD]
[TD]Regular[/TD]
[TD]3000902831[/TD]
[TD] [/TD]
[TD]000000625919[/TD]
[TD]00009-003[/TD]
[TD]124-171-0[/TD]
[TD]89[/TD]
[TD="align: right"]$1,813.48[/TD]
[TD="align: right"]1[/TD]
[/TR]
[TR]
[TD]30-Jul-2018[/TD]
[TD]CAL[/TD]
[TD]5309[/TD]
[TD]CAD[/TD]
[TD]Regular[/TD]
[TD]3000902833[/TD]
[TD] [/TD]
[TD]000001556277[/TD]
[TD]00009-003[/TD]
[TD]124-171-0[/TD]
[TD]89[/TD]
[TD="align: right"]$4,114.38[/TD]
[TD="align: right"]6[/TD]
[/TR]
[TR]
[TD]30-Jul-2018[/TD]
[TD]CAL[/TD]
[TD]5309[/TD]
[TD]CAD[/TD]
[TD]Regular[/TD]
[TD]3000902843[/TD]
[TD]00009[/TD]
[TD]0403[/TD]
[TD]00009-003[/TD]
[TD]119-016-4[/TD]
[TD]51[/TD]
[TD="align: right"]$32,642.70[/TD]
[TD="align: right"]3[/TD]
[/TR]
[TR]
[TD]30-Jul-2018[/TD]
[TD]CAL[/TD]
[TD]5309[/TD]
[TD]CAD[/TD]
[TD]Regular[/TD]
[TD]3000902847[/TD]
[TD]00009[/TD]
[TD]0580[/TD]
[TD]00009-003[/TD]
[TD]112-845-3[/TD]
[TD]51[/TD]
[TD="align: right"]$1,575.00[/TD]
[TD="align: right"]1[/TD]
[/TR]
[TR]
[TD]30-Jul-2018[/TD]
[TD]CAL[/TD]
[TD]5309[/TD]
[TD]CAD[/TD]
[TD]Regular[/TD]
[TD]3000902849[/TD]
[TD]00009[/TD]
[TD]0182[/TD]
[TD]00009-003[/TD]
[TD]123-794-0[/TD]
[TD]51[/TD]
[TD="align: right"]$20,222.70[/TD]
[TD="align: right"]1[/TD]
[/TR]
[TR]
[TD]30-Jul-2018[/TD]
[TD]CAL[/TD]
[TD]5309[/TD]
[TD]CAD[/TD]
[TD]Regular[/TD]
[TD]3000902851[/TD]
[TD]00009[/TD]
[TD]0290[/TD]
[TD]00009-003[/TD]
[TD]000-080-2[/TD]
[TD]51[/TD]
[TD="align: right"]$10,153.88[/TD]
[TD="align: right"]2[/TD]
[/TR]
[TR]
[TD]30-Jul-2018[/TD]
[TD]CAL[/TD]
[TD]5309[/TD]
[TD]CAD[/TD]
[TD]Regular[/TD]
[TD]3000902854[/TD]
[TD]00009[/TD]
[TD]0582[/TD]
[TD]00009-003[/TD]
[TD]103-762-1[/TD]
[TD]51[/TD]
[TD="align: right"]$132,862.91[/TD]
[TD="align: right"]2[/TD]
[/TR]
[TR]
[TD]30-Jul-2018[/TD]
[TD]CAL[/TD]
[TD]5309[/TD]
[TD]CAD[/TD]
[TD]Regular[/TD]
[TD]3000902857[/TD]
[TD]00009[/TD]
[TD]3102[/TD]
[TD]00009-003[/TD]
[TD]134-259-1[/TD]
[TD]51[/TD]
[TD="align: right"]$478,419.56[/TD]
[TD="align: right"]2[/TD]
[/TR]
[TR]
[TD]30-Jul-2018[/TD]
[TD]CAL[/TD]
[TD]5309[/TD]
[TD]CAD[/TD]
[TD]Regular[/TD]
[TD]3000902860[/TD]
[TD]00009[/TD]
[TD]0784[/TD]
[TD]00009-003[/TD]
[TD]000-035-6[/TD]
[TD]51[/TD]
[TD="align: right"]$132,670.77[/TD]
[TD="align: right"]3[/TD]
[/TR]
[TR]
[TD]30-Jul-2018[/TD]
[TD]CAL[/TD]
[TD]5309[/TD]
[TD]CAD[/TD]
[TD]Regular[/TD]
[TD]3000902864[/TD]
[TD]00009[/TD]
[TD]0026[/TD]
[TD]08519-003[/TD]
[TD]102-917-2[/TD]
[TD]51[/TD]
[TD="align: right"]$6,595.75[/TD]
[TD="align: right"]1[/TD]
[/TR]
[TR]
[TD]30-Jul-2018[/TD]
[TD]CAL[/TD]
[TD]5309[/TD]
[TD]CAD[/TD]
[TD]Regular[/TD]
[TD]3000902866[/TD]
[TD]00009[/TD]
[TD]4464[/TD]
[TD]00007-003[/TD]
[TD]000-006-7[/TD]
[TD]51[/TD]
[TD="align: right"]$54,658.50[/TD]
[TD="align: right"]4[/TD]
[/TR]
[TR]
[TD]30-Jul-2018[/TD]
[TD]CAL[/TD]
[TD]5309[/TD]
[TD]CAD[/TD]
[TD]Regular[/TD]
[TD]3000902871[/TD]
[TD]00009[/TD]
[TD] [/TD]
[TD]00009-003[/TD]
[TD]122-204-1[/TD]
[TD]51[/TD]
[TD="align: right"]$3,785.00[/TD]
[TD="align: right"]1[/TD]
[/TR]
[TR]
[TD]30-Jul-2018[/TD]
[TD]CAL[/TD]
[TD]5309[/TD]
[TD]CAD[/TD]
[TD]Regular[/TD]
[TD]3000902873[/TD]
[TD]00009[/TD]
[TD]0077[/TD]
[TD]00009-003[/TD]
[TD]147-274-5[/TD]
[TD]51[/TD]
[TD="align: right"]$642.00[/TD]
[TD="align: right"]1[/TD]
[/TR]
[TR]
[TD]30-Jul-2018[/TD]
[TD]CAL[/TD]
[TD]5309[/TD]
[TD]CAD[/TD]
[TD]Regular[/TD]
[TD]3000902877[/TD]
[TD]02539[/TD]
[TD] [/TD]
[TD]00009-003[/TD]
[TD]109-602-3[/TD]
[TD]51[/TD]
[TD="align: right"]$2,305.85[/TD]
[TD="align: right"]7[/TD]
[/TR]
[TR]
[TD]30-Jul-2018[/TD]
[TD]CAL[/TD]
[TD]5309[/TD]
[TD]CAD[/TD]
[TD]Regular[/TD]
[TD]3000902885[/TD]
[TD]02539[/TD]
[TD] [/TD]
[TD]00009-003[/TD]
[TD]109-686-6[/TD]
[TD]51[/TD]
[TD="align: right"]$350.20[/TD]
[TD="align: right"]2[/TD]
[/TR]
[TR]
[TD]30-Jul-2018[/TD]
[TD]CAL[/TD]
[TD]5309[/TD]
[TD]CAD[/TD]
[TD]Regular[/TD]
[TD]3000902888[/TD]
[TD]02539[/TD]
[TD] [/TD]
[TD]00009-003[/TD]
[TD]129-500-5[/TD]
[TD]51[/TD]
[TD="align: right"]$36.25[/TD]
[TD="align: right"]1[/TD]
[/TR]
[TR]
[TD]30-Jul-2018[/TD]
[TD]CAL[/TD]
[TD]5309[/TD]
[TD]CAD[/TD]
[TD]Regular[/TD]
[TD]3000902890[/TD]
[TD]02539[/TD]
[TD] [/TD]
[TD]00009-003[/TD]
[TD]129-531-0[/TD]
[TD]51[/TD]
[TD="align: right"]$30.00[/TD]
[TD="align: right"]1[/TD]
[/TR]
[TR]
[TD]30-Jul-2018[/TD]
[TD]CAL[/TD]
[TD]5309[/TD]
[TD]CAD[/TD]
[TD]Regular[/TD]
[TD]3000902892[/TD]
[TD]02539[/TD]
[TD] [/TD]
[TD]00009-003[/TD]
[TD]131-609-0[/TD]
[TD]51[/TD]
[TD="align: right"]$150.00[/TD]
[TD="align: right"]1[/TD]
[/TR]
[TR]
[TD]30-Jul-2018[/TD]
[TD]CAL[/TD]
[TD]5309[/TD]
[TD]CAD[/TD]
[TD]Regular[/TD]
[TD]3000902894[/TD]
[TD]02539[/TD]
[TD] [/TD]
[TD]00009-003[/TD]
[TD]131-608-2[/TD]
[TD]51[/TD]
[TD="align: right"]$150.00[/TD]
[TD="align: right"]1[/TD]
[/TR]
[TR]
[TD]30-Jul-2018[/TD]
[TD]CAL[/TD]
[TD]5309[/TD]
[TD]CAD[/TD]
[TD]Regular[/TD]
[TD]3000902896[/TD]
[TD]02539[/TD]
[TD] [/TD]
[TD]00009-003[/TD]
[TD]109-602-3[/TD]
[TD]51[/TD]
[TD="align: right"]$1,636.00[/TD]
[TD="align: right"]1[/TD]
[/TR]
[TR]
[TD]30-Jul-2018[/TD]
[TD]CAL[/TD]
[TD]5309[/TD]
[TD]CAD[/TD]
[TD]Regular[/TD]
[TD]3000902898[/TD]
[TD]02539[/TD]
[TD] [/TD]
[TD]00009-003[/TD]
[TD]109-686-6[/TD]
[TD]51[/TD]
[TD="align: right"]$3,371.11[/TD]
[TD="align: right"]1[/TD]
[/TR]
</tbody>[/TABLE]
 
Last edited by a moderator:
Upvote 0
What row does your header and data start on before running any macros?
 
Upvote 0
What row does your header and data start on before running any macros?

I run another macro to merge other worksheets into the "Combined" tab and somehow it triplicates the header row. In other words, for this macro in question, the top 3 rows are always the same headers, therefore I need to delete 2 of them. Data starts with the 4th row prior to running this macro.
 
Upvote 0
So it looks like that you are summarizing the data in columns N-R.
But when you copy over to your Results tab, you are copying columns A-R. So of the values in columns A-M are being cut off.
Do you care about the data in those columns for your Results tab, or just the summarized data?
 
Upvote 0
Columns A to M are the before-consolidation data, therefore I don't need them. I also don't need column N because that's basically joint values of columns D+I+J.
Column O is the "unique records" out of column N via advanced filter, therefore is what I copy along with columns P and Q (P and Q are the SUMIF totals, which is the information I need from this whole exercise). In other words, I need columns O,P,Q but column O needs to be separated (i.e. text-to-column) into 3 different fields (i.e. originally columns D, I, J).

Hope I'm not confusing you.
 
Last edited by a moderator:
Upvote 0
OK, I think this should give you what you want:
Code:
Sub Convert()
'
' Convert Macro
'
'
    Dim mySource As Worksheet
    Dim myTarget As Worksheet
    Dim lastRow As Long
    
    Set mySource = ActiveWorkbook.Worksheets("Combined")
    Set myTarget = ActiveWorkbook.Worksheets("Results")

    Application.ScreenUpdating = False
    Application.Calculation = xlCalculationManual

    Sheets("Combined").Select

    Rows("1:2").Delete Shift:=xlUp

    With Columns("J:J")
        .Replace What:="~*", Replacement:="#", LookAt:=xlPart, _
            SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
            ReplaceFormat:=False
        .Replace What:="~?", Replacement:="/", LookAt:=xlPart, _
            SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
            ReplaceFormat:=False
        .Replace What:="/", Replacement:="?", LookAt:=xlPart, _
            SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
            ReplaceFormat:=False
        .Replace What:="#", Replacement:="*", LookAt:=xlPart, _
            SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
            ReplaceFormat:=False
    End With
    
'   Find last row with data in column A
    lastRow = Cells(Rows.Count, "A").End(xlUp).Row
    
    Range("N2:N" & lastRow).FormulaR1C1 = "=RC[-10]&"",""&RC[-5]&"",""&RC[-4]"
    Range("N2:N" & lastRow).Value = Range("N2:N" & lastRow).Value

    Range("N2:N" & lastRow).AdvancedFilter Action:=xlFilterCopy, CopyToRange:=Range( _
        "O2"), Unique:=True

'   Remove any duplicates left after filter
    Application.DisplayAlerts = False
    Range("O2:O" & lastRow).RemoveDuplicates Columns:=1, Header:=xlNo
    
'   Find new last row, using column O
    lastRow = Cells(Rows.Count, "O").End(xlUp).Row

    Range("P2:P" & lastRow).FormulaR1C1 = "=SUMIF(C[-2],RC[-1],C[-4])"
    Range("Q2:Q" & lastRow).FormulaR1C1 = "=SUMIF(C[-3],RC[-2],C[-4])"
    Range("P2:Q" & lastRow).Value = Range("P2:Q" & lastRow).Value

    Columns("P:P").NumberFormat = "#,##0.00"
    Columns("Q:Q").NumberFormat = "#,##0"

'   Copy data to target sheet
    mySource.Range("O2:Q" & lastRow).Copy myTarget.Range("A2")

    Sheets("Convert").Select
    Range("C3").Select
    
    Application.Calculation = xlCalculationAutomatic
    Application.ScreenUpdating = True
    
End Sub
 
Upvote 0
Wow, the speed improvement is totally amazing. My original code took about 2-3 minutes but yours was INSTANT!!!!!
There's only a problem with some cells having wildcard values. I tried to look at the codes but really know have enough VBA knowledge to figure out anything, so maybe you can help one final time (really appreciate your time). I have revised the sample data so you can test with this:
[TABLE="width: 871"]
<colgroup><col span="2"><col span="3"><col><col span="3"><col><col><col><col></colgroup><tbody>[TR]
[TD]ReportDate[/TD]
[TD]Region[/TD]
[TD]Entry[/TD]
[TD]Currency[/TD]
[TD]WorkType[/TD]
[TD]ISN[/TD]
[TD]Branch Transit[/TD]
[TD]SERIAL[/TD]
[TD]Cr_RT[/TD]
[TD]Cr_Acct[/TD]
[TD]TRANCODE[/TD]
[TD]AMOUNT[/TD]
[TD]CountOfItems[/TD]
[/TR]
[TR]
[TD]ReportDate[/TD]
[TD]Region[/TD]
[TD]Entry[/TD]
[TD]Currency[/TD]
[TD]WorkType[/TD]
[TD]ISN[/TD]
[TD]Branch Transit[/TD]
[TD]SERIAL[/TD]
[TD]Cr_RT[/TD]
[TD]Cr_Acct[/TD]
[TD]TRANCODE[/TD]
[TD]AMOUNT[/TD]
[TD]CountOfItems[/TD]
[/TR]
[TR]
[TD]ReportDate[/TD]
[TD]Region[/TD]
[TD]Entry[/TD]
[TD]Currency[/TD]
[TD]WorkType[/TD]
[TD]ISN[/TD]
[TD]Branch Transit[/TD]
[TD]SERIAL[/TD]
[TD]Cr_RT[/TD]
[TD]Cr_Acct[/TD]
[TD]TRANCODE[/TD]
[TD]AMOUNT[/TD]
[TD]CountOfItems[/TD]
[/TR]
[TR]
[TD="align: right"]30-Jul-18[/TD]
[TD]CAL[/TD]
[TD]5309[/TD]
[TD]CAD[/TD]
[TD]Regular[/TD]
[TD]3000902814[/TD]
[TD][/TD]
[TD]694367[/TD]
[TD]00009-003[/TD]
[TD]124-171-0[/TD]
[TD]89[/TD]
[TD="align: right"]$5,238.25[/TD]
[TD="align: right"]7[/TD]
[/TR]
[TR]
[TD="align: right"]30-Jul-18[/TD]
[TD]CAL[/TD]
[TD]5309[/TD]
[TD]CAD[/TD]
[TD]Regular[/TD]
[TD]3000902822[/TD]
[TD][/TD]
[TD]1586165[/TD]
[TD]00009-003[/TD]
[TD]124-171-0[/TD]
[TD]89[/TD]
[TD="align: right"]$4,967.13[/TD]
[TD="align: right"]8[/TD]
[/TR]
[TR]
[TD="align: right"]30-Jul-18[/TD]
[TD]CAL[/TD]
[TD]5309[/TD]
[TD]CAD[/TD]
[TD]Regular[/TD]
[TD]3000902831[/TD]
[TD][/TD]
[TD]625919[/TD]
[TD]00009-003[/TD]
[TD]124-171-0[/TD]
[TD]89[/TD]
[TD="align: right"]$1,813.48[/TD]
[TD="align: right"]1[/TD]
[/TR]
[TR]
[TD="align: right"]30-Jul-18[/TD]
[TD]CAL[/TD]
[TD]5309[/TD]
[TD]CAD[/TD]
[TD]Regular[/TD]
[TD]3000902833[/TD]
[TD][/TD]
[TD]1556277[/TD]
[TD]00009-003[/TD]
[TD]124-171-0[/TD]
[TD]89[/TD]
[TD="align: right"]$4,114.38[/TD]
[TD="align: right"]6[/TD]
[/TR]
[TR]
[TD="align: right"]30-Jul-18[/TD]
[TD]CAL[/TD]
[TD]5309[/TD]
[TD]CAD[/TD]
[TD]Regular[/TD]
[TD]3000902843[/TD]
[TD]9[/TD]
[TD]403[/TD]
[TD]00009-003[/TD]
[TD]119-016-4[/TD]
[TD]51[/TD]
[TD="align: right"]$32,642.70[/TD]
[TD="align: right"]3[/TD]
[/TR]
[TR]
[TD="align: right"]30-Jul-18[/TD]
[TD]CAL[/TD]
[TD]5309[/TD]
[TD]CAD[/TD]
[TD]Regular[/TD]
[TD]3000902847[/TD]
[TD]9[/TD]
[TD]580[/TD]
[TD]00009-003[/TD]
[TD]************[/TD]
[TD]51[/TD]
[TD="align: right"]$1,575.00[/TD]
[TD="align: right"]1[/TD]
[/TR]
[TR]
[TD="align: right"]30-Jul-18[/TD]
[TD]CAL[/TD]
[TD]5309[/TD]
[TD]CAD[/TD]
[TD]Regular[/TD]
[TD]3000902849[/TD]
[TD]9[/TD]
[TD]182[/TD]
[TD]00009-003[/TD]
[TD]123-794-0[/TD]
[TD]51[/TD]
[TD="align: right"]$20,222.70[/TD]
[TD="align: right"]1[/TD]
[/TR]
[TR]
[TD="align: right"]30-Jul-18[/TD]
[TD]CAL[/TD]
[TD]5309[/TD]
[TD]CAD[/TD]
[TD]Regular[/TD]
[TD]3000902851[/TD]
[TD]9[/TD]
[TD]290[/TD]
[TD]00009-003[/TD]
[TD]000-080-2[/TD]
[TD]51[/TD]
[TD="align: right"]$10,153.88[/TD]
[TD="align: right"]2[/TD]
[/TR]
[TR]
[TD="align: right"]30-Jul-18[/TD]
[TD]CAL[/TD]
[TD]5309[/TD]
[TD]CAD[/TD]
[TD]Regular[/TD]
[TD]3000902854[/TD]
[TD]9[/TD]
[TD]582[/TD]
[TD]00009-003[/TD]
[TD]103-7*2-1[/TD]
[TD]51[/TD]
[TD="align: right"]$132,862.91[/TD]
[TD="align: right"]2[/TD]
[/TR]
[TR]
[TD="align: right"]30-Jul-18[/TD]
[TD]CAL[/TD]
[TD]5309[/TD]
[TD]CAD[/TD]
[TD]Regular[/TD]
[TD]3000902857[/TD]
[TD]9[/TD]
[TD]3102[/TD]
[TD]00009-003[/TD]
[TD]134-259-1[/TD]
[TD]51[/TD]
[TD="align: right"]$478,419.56[/TD]
[TD="align: right"]2[/TD]
[/TR]
[TR]
[TD="align: right"]30-Jul-18[/TD]
[TD]CAL[/TD]
[TD]5309[/TD]
[TD]CAD[/TD]
[TD]Regular[/TD]
[TD]3000902860[/TD]
[TD]9[/TD]
[TD]784[/TD]
[TD]00009-003[/TD]
[TD]????????[/TD]
[TD]51[/TD]
[TD="align: right"]$132,670.77[/TD]
[TD="align: right"]3[/TD]
[/TR]
[TR]
[TD="align: right"]30-Jul-18[/TD]
[TD]CAL[/TD]
[TD]5309[/TD]
[TD]CAD[/TD]
[TD]Regular[/TD]
[TD]3000902864[/TD]
[TD]9[/TD]
[TD]26[/TD]
[TD]08519-003[/TD]
[TD]102-917-2[/TD]
[TD]51[/TD]
[TD="align: right"]$6,595.75[/TD]
[TD="align: right"]1[/TD]
[/TR]
[TR]
[TD="align: right"]30-Jul-18[/TD]
[TD]CAL[/TD]
[TD]5309[/TD]
[TD]CAD[/TD]
[TD]Regular[/TD]
[TD]3000902866[/TD]
[TD]9[/TD]
[TD]4464[/TD]
[TD]00007-003[/TD]
[TD]0?0-006-7[/TD]
[TD]51[/TD]
[TD="align: right"]$54,658.50[/TD]
[TD="align: right"]4[/TD]
[/TR]
[TR]
[TD="align: right"]30-Jul-18[/TD]
[TD]CAL[/TD]
[TD]5309[/TD]
[TD]CAD[/TD]
[TD]Regular[/TD]
[TD]3000902871[/TD]
[TD]9[/TD]
[TD][/TD]
[TD]00009-003[/TD]
[TD]122-204-1[/TD]
[TD]51[/TD]
[TD="align: right"]$3,785.00[/TD]
[TD="align: right"]1[/TD]
[/TR]
[TR]
[TD="align: right"]30-Jul-18[/TD]
[TD]CAL[/TD]
[TD]5309[/TD]
[TD]CAD[/TD]
[TD]Regular[/TD]
[TD]3000902873[/TD]
[TD]9[/TD]
[TD]77[/TD]
[TD]00009-003[/TD]
[TD]147-274-5[/TD]
[TD]51[/TD]
[TD="align: right"]$642.00[/TD]
[TD="align: right"]1[/TD]
[/TR]
[TR]
[TD="align: right"]30-Jul-18[/TD]
[TD]CAL[/TD]
[TD]5309[/TD]
[TD]CAD[/TD]
[TD]Regular[/TD]
[TD]3000902877[/TD]
[TD]2539[/TD]
[TD][/TD]
[TD]00009-003[/TD]
[TD]?09-602-3[/TD]
[TD]51[/TD]
[TD="align: right"]$2,305.85[/TD]
[TD="align: right"]7[/TD]
[/TR]
[TR]
[TD="align: right"]30-Jul-18[/TD]
[TD]CAL[/TD]
[TD]5309[/TD]
[TD]CAD[/TD]
[TD]Regular[/TD]
[TD]3000902885[/TD]
[TD]2539[/TD]
[TD][/TD]
[TD]00009-003[/TD]
[TD]109-686-6[/TD]
[TD]51[/TD]
[TD="align: right"]$350.20[/TD]
[TD="align: right"]2[/TD]
[/TR]
[TR]
[TD="align: right"]30-Jul-18[/TD]
[TD]CAL[/TD]
[TD]5309[/TD]
[TD]CAD[/TD]
[TD]Regular[/TD]
[TD]3000902888[/TD]
[TD]2539[/TD]
[TD][/TD]
[TD]00009-003[/TD]
[TD]??3-888-8[/TD]
[TD]51[/TD]
[TD="align: right"]$36.25[/TD]
[TD="align: right"]1[/TD]
[/TR]
[TR]
[TD="align: right"]30-Jul-18[/TD]
[TD]CAL[/TD]
[TD]5309[/TD]
[TD]CAD[/TD]
[TD]Regular[/TD]
[TD]3000902890[/TD]
[TD]2539[/TD]
[TD][/TD]
[TD]00009-003[/TD]
[TD]129-531-0[/TD]
[TD]51[/TD]
[TD="align: right"]$30.00[/TD]
[TD="align: right"]1[/TD]
[/TR]
[TR]
[TD="align: right"]30-Jul-18[/TD]
[TD]CAL[/TD]
[TD]5309[/TD]
[TD]CAD[/TD]
[TD]Regular[/TD]
[TD]3000902892[/TD]
[TD]2539[/TD]
[TD][/TD]
[TD]00009-003[/TD]
[TD]131-609-0[/TD]
[TD]51[/TD]
[TD="align: right"]$150.00[/TD]
[TD="align: right"]1[/TD]
[/TR]
[TR]
[TD="align: right"]30-Jul-18[/TD]
[TD]CAL[/TD]
[TD]5309[/TD]
[TD]CAD[/TD]
[TD]Regular[/TD]
[TD]3000902894[/TD]
[TD]2539[/TD]
[TD][/TD]
[TD]00009-003[/TD]
[TD]131-608-2[/TD]
[TD]51[/TD]
[TD="align: right"]$150.00[/TD]
[TD="align: right"]1[/TD]
[/TR]
[TR]
[TD="align: right"]30-Jul-18[/TD]
[TD]CAL[/TD]
[TD]5309[/TD]
[TD]CAD[/TD]
[TD]Regular[/TD]
[TD]3000902896[/TD]
[TD]2539[/TD]
[TD][/TD]
[TD]00009-003[/TD]
[TD]*09-602-3[/TD]
[TD]51[/TD]
[TD="align: right"]$1,636.00[/TD]
[TD="align: right"]1[/TD]
[/TR]
[TR]
[TD="align: right"]30-Jul-18[/TD]
[TD]CAL[/TD]
[TD]5309[/TD]
[TD]CAD[/TD]
[TD]Regular[/TD]
[TD]3000902898[/TD]
[TD]2539[/TD]
[TD][/TD]
[TD]00009-003[/TD]
[TD]109-686-6[/TD]
[TD]51[/TD]
[TD="align: right"]$3,371.11[/TD]
[TD="align: right"]1[/TD]
[/TR]
</tbody>[/TABLE]
 
Upvote 0
There's only a problem with some cells having wildcard values.
Can you explain exactly what you want to happen with these?

In this first part of your original code, you have it changing "*" to "#" and changing "?" to "/".
But later in the same code, you seem to be changing it back, changing "/" back to "?", and changing "#" back to "*".

Was this intentional? Are you only changing the values long enough to build the strings, and then changing them back?
 
Upvote 0

Forum statistics

Threads
1,224,818
Messages
6,181,152
Members
453,021
Latest member
Justyna P

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