VBA Code Question

Excel_Assis

Board Regular
Joined
Feb 19, 2011
Messages
132
Office Version
  1. 2016
Platform
  1. Windows
Could someone please help with the following.


For i = 37 To .Range("B" & .Rows.Count).End(xlUp).Row
If .Range("E" & i).Value <> "" Then
.Range("E" & i).Offset(0, -1).Value = .Range("E" & i).Value
End If



The code works to line starting with For i = 37 To .Range
then skips over the rest. It all worked fine on another spread sheet.
 

Excel Facts

Format cells as time
Select range and press Ctrl+Shift+2 to format cells as time. (Shift 2 is the @ sign).
Guys if I run this part of the macro on this data it works fine.

Sub Button1_Click()
'Sub Advanced_Filter_Sheet3()
Dim wsSrc As Worksheet: Set wsSrc = Sheets("Sheet1")
Dim wsDest As Worksheet: Set wsDest = Sheets("Sheet2")
Dim wsDestSum As Worksheet: Set wsDestSum = Sheets("Sheet3")
Dim i As Long
With wsDest
.UsedRange.Clear
wsSrc.Range("B8:B22,E8:E22,I8:I22,K8:K22").Copy .Range("B10")


For i = 11 To .Range("B" & .Rows.Count).End(xlUp).Row
If .Range("E" & i).Value <> "" Then
.Range("E" & i).Offset(0, -1).Value = .Range("E" & i).Value
End If
Next i

.Columns("E").Delete
.Range("B10:D40").AdvancedFilter Action:=xlFilterCopy, _
CopyToRange:=.Range("E10"), Unique:=True
.Columns("B:D").Delete
End With


Excel Workbook
BCDE
10ITEMACC No.JOB NO. AJOB NO. B
11Cat1000512349876
12Dog100031234
13Rat100061234
14Pig100081234
15Rat100061234
16Dog100039876
17Dog100031234
18Pig100089876
19Cat100051234
20Dog100036789
21Bird101101111
22Horse101183232
23Dog100033245
24Bull188888787
Sheet2





But if I run the same part of the macro on this data it does not work.


Excel Workbook
BCDE
10ITEMACC No.JOB NO. AJOB NO. B
11Field Hand Services9-012010462021
12SURVEYS9-04009999
13Petty Cash1-110910692099
14Training/Conferences/Courses9-01251021
15Drafting & Computing Services9-01151046
16Payroll Recoveries6-10991000
17Staff Paye2-21011021
18Management Fees4-30002070
19Management Fees4-30002020
20Director Fees6-10912047
21Vehicle Operating Costs9-076010322069
22
23
24
Sheet2



I have no idea why. Any suggestions.
 
Upvote 0
Did you try Hyats method of stepping through the code using F8 to see what happens at each line ?
I can't see why sample 1 is working and sample 2 is not!
 
Upvote 0
Excel_Assis, I tried pasting the second sample of data you gave in columns B, E, I, and K of sheet 1 respectively, and running the code. It worked ok.

Maybe there's a difference in how/where you're pasting sample 1 and sample 2? Or alternatively maybe you have put sample 1 and sample 2 in different ranges / sheets?
 
Last edited:
Upvote 0
Hi Guys after stepping through the code using f8 at this point in the code last line shown below (.Columns("B:D").Delete) on Sample 1 I am left with the following:

'Sub Advanced_Filter_Sheet3()
Dim wsSrc As Worksheet: Set wsSrc = Sheets("Sheet1")
Dim wsDest As Worksheet: Set wsDest = Sheets("Sheet2")
Dim wsDestSum As Worksheet: Set wsDestSum = Sheets("Sheet3")
Dim i As Long
With wsDest
.UsedRange.Clear
wsSrc.Range("B8:B22,E8:E22,I8:I22,K8:K22").Copy .Range("B10")


For i = 15 To .Range("B" & .Rows.Count).End(xlUp).Row
If .Range("E" & i).Value <> "" Then
.Range("E" & i).Offset(0, -1).Value = .Range("E" & i).Value
End If
Next i

.Columns("E").Delete
.Range("B10:D40").AdvancedFilter Action:=xlFilterCopy, _
CopyToRange:=.Range("E10"), Unique:=True
.Columns("B:D").Delete




Excel Workbook
BCDEFG
10ITEMACC No.JOB NO. AITEMACC No.JOB NO. A
11Cat100051234Cat100051234
12Dog100031234Dog100031234
13Rat100061234Rat100061234
14Pig100081234Pig100081234
15Rat100061234Dog100039876
16Dog100039876Pig100089876
17Dog100031234Dog100036789
18Pig100089876Bird101101111
19Cat100051234Horse101183232
20Dog100036789Dog100033245
21Bird101101111Bull188888787
22Horse101183232
23Dog100033245
24Bull188888787
25
Sheet2


At the same point in the code of Sample2 I am left with this:

As you can see both columns are the same here not like in Samlpe 1 where it shows the differences.


Excel Workbook
BCDEFG
10ITEMACC No.JOB NO. AITEMACC No.JOB NO. A
11Field Hand Services9-01201046Field Hand Services9-01201046
12SURVEYS9-04009999SURVEYS9-04009999
13Petty Cash1-11091069Petty Cash1-11091069
14Training/Conferences/Courses9-01251021Training/Conferences/Courses9-01251021
15Drafting & Computing Services9-01151046Drafting & Computing Services9-01151046
16Payroll Recoveries6-10991000Payroll Recoveries6-10991000
17Staff Paye2-21011021Staff Paye2-21011021
18Management Fees4-30002070Management Fees4-30002070
19Management Fees4-30002020Management Fees4-30002020
20Director Fees6-10912047Director Fees6-10912047
21Vehicle Operating Costs9-07602069Vehicle Operating Costs9-07602069
22
23
24
25
Sheet2
 
Upvote 0
That may be because in Sample 1, there were 3 non-unique rows that AdvancedFilter got rid of whereas in Sample 2, each row is unique...
 
Upvote 0
Here is the data from sheet1 as you can see on the first row of data the is for example two Field Hand Services with unique Jobs No. Job No. A and Job No. B it should create a record for this on sheet2 like it does in sample 1 for the dog.

Excel Workbook
ABCDEFGHIJKL
8DATEITEMACC No.US$RECEIPTJOB NO. AJOB A US$JOB NO. BJOB B US$
9Field Hand Services9-0120R5000$1.221046$0.612021$0.61
10SURVEYS9-0400R70$0.029999$0.02
11Petty Cash1-1109$2.00$2.001069$1.002099$1.00
12Training/Conferences/Courses9-0125$0.001021$0.00
13Drafting & Computing Services9-0115R20000$4.881046$4.88
14Payroll Recoveries6-1099R500000$121.951000$121.95
15Staff Paye2-2101R470$0.111021$0.11
16Management Fees4-3000$10,000.00$10,000.002070$10,000.00
17Management Fees4-3000$9,000.00$9,000.002020$9,000.00
18Director Fees6-1091$25,000.00$25,000.002047$25,000.00
19Vehicle Operating Costs9-0760$550.00$550.001032$275.002069$275.00
20$0.00
21$0.00
22$0.00
230
240
25
Sheet1
 
Upvote 0
But I don't see any records being created for dog. I do however see that three records (highlighted in yellow) appearing in columns A:C are not appearing in columns D:F. AdvancedFilter has filtered these out because they were not unique. If you are looking to create new records, then perhaps you shouldn't be using AdvancedFilter.

Sheet2

<TABLE style="BACKGROUND-COLOR: #ffffff; PADDING-LEFT: 2pt; PADDING-RIGHT: 2pt; FONT-FAMILY: Calibri,Arial; FONT-SIZE: 11pt" border=1 cellSpacing=0 cellPadding=0><COLGROUP><COL style="WIDTH: 30px; FONT-WEIGHT: bold"><COL style="WIDTH: 64px"><COL style="WIDTH: 64px"><COL style="WIDTH: 64px"><COL style="WIDTH: 64px"><COL style="WIDTH: 64px"><COL style="WIDTH: 64px"></COLGROUP><TBODY><TR style="TEXT-ALIGN: center; BACKGROUND-COLOR: #cacaca; FONT-SIZE: 8pt; FONT-WEIGHT: bold"><TD> </TD><TD>A</TD><TD>B</TD><TD>C</TD><TD>D</TD><TD>E</TD><TD>F</TD></TR><TR style="HEIGHT: 32px"><TD style="TEXT-ALIGN: center; BACKGROUND-COLOR: #cacaca; FONT-SIZE: 8pt">10</TD><TD style="BACKGROUND-COLOR: #33cccc; FONT-FAMILY: Verdana; COLOR: #ffffff; FONT-SIZE: 10pt; FONT-WEIGHT: bold">ITEM</TD><TD style="TEXT-ALIGN: center; BACKGROUND-COLOR: #33cccc; FONT-FAMILY: Verdana; COLOR: #ffffff; FONT-SIZE: 10pt; FONT-WEIGHT: bold">ACC No.</TD><TD style="BACKGROUND-COLOR: #33cccc; FONT-FAMILY: Verdana; COLOR: #ffffff; FONT-SIZE: 10pt; FONT-WEIGHT: bold">JOB NO. A</TD><TD style="BACKGROUND-COLOR: #33cccc; FONT-FAMILY: Verdana; COLOR: #ffffff; FONT-SIZE: 10pt; FONT-WEIGHT: bold">ITEM</TD><TD style="TEXT-ALIGN: center; BACKGROUND-COLOR: #33cccc; FONT-FAMILY: Verdana; COLOR: #ffffff; FONT-SIZE: 10pt; FONT-WEIGHT: bold">ACC No.</TD><TD style="BACKGROUND-COLOR: #33cccc; FONT-FAMILY: Verdana; COLOR: #ffffff; FONT-SIZE: 10pt; FONT-WEIGHT: bold">JOB NO. A</TD></TR><TR style="HEIGHT: 18px"><TD style="TEXT-ALIGN: center; BACKGROUND-COLOR: #cacaca; FONT-SIZE: 8pt">11</TD><TD style="FONT-FAMILY: Verdana; FONT-SIZE: 10pt">Cat</TD><TD style="TEXT-ALIGN: center; FONT-FAMILY: Verdana; FONT-SIZE: 10pt">10005</TD><TD style="TEXT-ALIGN: right; BACKGROUND-COLOR: #c0c0c0; FONT-FAMILY: Verdana; FONT-SIZE: 10pt">1234</TD><TD style="FONT-FAMILY: Verdana; FONT-SIZE: 10pt">Cat</TD><TD style="TEXT-ALIGN: center; FONT-FAMILY: Verdana; FONT-SIZE: 10pt">10005</TD><TD style="TEXT-ALIGN: right; BACKGROUND-COLOR: #c0c0c0; FONT-FAMILY: Verdana; FONT-SIZE: 10pt">1234</TD></TR><TR style="HEIGHT: 18px"><TD style="TEXT-ALIGN: center; BACKGROUND-COLOR: #cacaca; FONT-SIZE: 8pt">12</TD><TD style="FONT-FAMILY: Verdana; FONT-SIZE: 10pt">Dog</TD><TD style="TEXT-ALIGN: center; FONT-FAMILY: Verdana; FONT-SIZE: 10pt">10003</TD><TD style="TEXT-ALIGN: right; BACKGROUND-COLOR: #c0c0c0; FONT-FAMILY: Verdana; FONT-SIZE: 10pt">1234</TD><TD style="FONT-FAMILY: Verdana; FONT-SIZE: 10pt">Dog</TD><TD style="TEXT-ALIGN: center; FONT-FAMILY: Verdana; FONT-SIZE: 10pt">10003</TD><TD style="TEXT-ALIGN: right; BACKGROUND-COLOR: #c0c0c0; FONT-FAMILY: Verdana; FONT-SIZE: 10pt">1234</TD></TR><TR style="HEIGHT: 18px"><TD style="TEXT-ALIGN: center; BACKGROUND-COLOR: #cacaca; FONT-SIZE: 8pt">13</TD><TD style="FONT-FAMILY: Verdana; FONT-SIZE: 10pt">Rat</TD><TD style="TEXT-ALIGN: center; FONT-FAMILY: Verdana; FONT-SIZE: 10pt">10006</TD><TD style="TEXT-ALIGN: right; BACKGROUND-COLOR: #c0c0c0; FONT-FAMILY: Verdana; FONT-SIZE: 10pt">1234</TD><TD style="FONT-FAMILY: Verdana; FONT-SIZE: 10pt">Rat</TD><TD style="TEXT-ALIGN: center; FONT-FAMILY: Verdana; FONT-SIZE: 10pt">10006</TD><TD style="TEXT-ALIGN: right; BACKGROUND-COLOR: #c0c0c0; FONT-FAMILY: Verdana; FONT-SIZE: 10pt">1234</TD></TR><TR style="HEIGHT: 18px"><TD style="TEXT-ALIGN: center; BACKGROUND-COLOR: #cacaca; FONT-SIZE: 8pt">14</TD><TD style="FONT-FAMILY: Verdana; FONT-SIZE: 10pt">Pig</TD><TD style="TEXT-ALIGN: center; FONT-FAMILY: Verdana; FONT-SIZE: 10pt">10008</TD><TD style="TEXT-ALIGN: right; BACKGROUND-COLOR: #c0c0c0; FONT-FAMILY: Verdana; FONT-SIZE: 10pt">1234</TD><TD style="FONT-FAMILY: Verdana; FONT-SIZE: 10pt">Pig</TD><TD style="TEXT-ALIGN: center; FONT-FAMILY: Verdana; FONT-SIZE: 10pt">10008</TD><TD style="TEXT-ALIGN: right; BACKGROUND-COLOR: #c0c0c0; FONT-FAMILY: Verdana; FONT-SIZE: 10pt">1234</TD></TR><TR style="HEIGHT: 18px"><TD style="TEXT-ALIGN: center; BACKGROUND-COLOR: #cacaca; FONT-SIZE: 8pt">15</TD><TD style="BACKGROUND-COLOR: #ffff00; FONT-FAMILY: Verdana; FONT-SIZE: 10pt">Rat</TD><TD style="TEXT-ALIGN: center; BACKGROUND-COLOR: #ffff00; FONT-FAMILY: Verdana; FONT-SIZE: 10pt">10006</TD><TD style="TEXT-ALIGN: right; BACKGROUND-COLOR: #ffff00; FONT-FAMILY: Verdana; FONT-SIZE: 10pt">1234</TD><TD style="FONT-FAMILY: Verdana; FONT-SIZE: 10pt">Dog</TD><TD style="TEXT-ALIGN: center; FONT-FAMILY: Verdana; FONT-SIZE: 10pt">10003</TD><TD style="TEXT-ALIGN: right; BACKGROUND-COLOR: #c0c0c0; FONT-FAMILY: Verdana; FONT-SIZE: 10pt">9876</TD></TR><TR style="HEIGHT: 18px"><TD style="TEXT-ALIGN: center; BACKGROUND-COLOR: #cacaca; FONT-SIZE: 8pt">16</TD><TD style="FONT-FAMILY: Verdana; FONT-SIZE: 10pt">Dog</TD><TD style="TEXT-ALIGN: center; FONT-FAMILY: Verdana; FONT-SIZE: 10pt">10003</TD><TD style="TEXT-ALIGN: right; BACKGROUND-COLOR: #c0c0c0; FONT-FAMILY: Verdana; FONT-SIZE: 10pt">9876</TD><TD style="FONT-FAMILY: Verdana; FONT-SIZE: 10pt">Pig</TD><TD style="TEXT-ALIGN: center; FONT-FAMILY: Verdana; FONT-SIZE: 10pt">10008</TD><TD style="TEXT-ALIGN: right; BACKGROUND-COLOR: #c0c0c0; FONT-FAMILY: Verdana; FONT-SIZE: 10pt">9876</TD></TR><TR style="HEIGHT: 18px"><TD style="TEXT-ALIGN: center; BACKGROUND-COLOR: #cacaca; FONT-SIZE: 8pt">17</TD><TD style="BACKGROUND-COLOR: #ffff00; FONT-FAMILY: Verdana; FONT-SIZE: 10pt">Dog</TD><TD style="TEXT-ALIGN: center; BACKGROUND-COLOR: #ffff00; FONT-FAMILY: Verdana; FONT-SIZE: 10pt">10003</TD><TD style="TEXT-ALIGN: right; BACKGROUND-COLOR: #ffff00; FONT-FAMILY: Verdana; FONT-SIZE: 10pt">1234</TD><TD style="FONT-FAMILY: Verdana; FONT-SIZE: 10pt">Dog</TD><TD style="TEXT-ALIGN: center; FONT-FAMILY: Verdana; FONT-SIZE: 10pt">10003</TD><TD style="TEXT-ALIGN: right; BACKGROUND-COLOR: #c0c0c0; FONT-FAMILY: Verdana; FONT-SIZE: 10pt">6789</TD></TR><TR style="HEIGHT: 18px"><TD style="TEXT-ALIGN: center; BACKGROUND-COLOR: #cacaca; FONT-SIZE: 8pt">18</TD><TD style="FONT-FAMILY: Verdana; FONT-SIZE: 10pt">Pig</TD><TD style="TEXT-ALIGN: center; FONT-FAMILY: Verdana; FONT-SIZE: 10pt">10008</TD><TD style="TEXT-ALIGN: right; BACKGROUND-COLOR: #c0c0c0; FONT-FAMILY: Verdana; FONT-SIZE: 10pt">9876</TD><TD style="FONT-FAMILY: Verdana; FONT-SIZE: 10pt">Bird</TD><TD style="TEXT-ALIGN: center; FONT-FAMILY: Verdana; FONT-SIZE: 10pt">10110</TD><TD style="TEXT-ALIGN: right; BACKGROUND-COLOR: #c0c0c0; FONT-FAMILY: Verdana; FONT-SIZE: 10pt">1111</TD></TR><TR style="HEIGHT: 18px"><TD style="TEXT-ALIGN: center; BACKGROUND-COLOR: #cacaca; FONT-SIZE: 8pt">19</TD><TD style="BACKGROUND-COLOR: #ffff00; FONT-FAMILY: Verdana; FONT-SIZE: 10pt">Cat</TD><TD style="TEXT-ALIGN: center; BACKGROUND-COLOR: #ffff00; FONT-FAMILY: Verdana; FONT-SIZE: 10pt">10005</TD><TD style="TEXT-ALIGN: right; BACKGROUND-COLOR: #ffff00; FONT-FAMILY: Verdana; FONT-SIZE: 10pt">1234</TD><TD style="FONT-FAMILY: Verdana; FONT-SIZE: 10pt">Horse</TD><TD style="TEXT-ALIGN: center; FONT-FAMILY: Verdana; FONT-SIZE: 10pt">10118</TD><TD style="TEXT-ALIGN: right; BACKGROUND-COLOR: #c0c0c0; FONT-FAMILY: Verdana; FONT-SIZE: 10pt">3232</TD></TR><TR style="HEIGHT: 18px"><TD style="TEXT-ALIGN: center; BACKGROUND-COLOR: #cacaca; FONT-SIZE: 8pt">20</TD><TD style="FONT-FAMILY: Verdana; FONT-SIZE: 10pt">Dog</TD><TD style="TEXT-ALIGN: center; FONT-FAMILY: Verdana; FONT-SIZE: 10pt">10003</TD><TD style="TEXT-ALIGN: right; BACKGROUND-COLOR: #c0c0c0; FONT-FAMILY: Verdana; FONT-SIZE: 10pt">6789</TD><TD style="FONT-FAMILY: Verdana; FONT-SIZE: 10pt">Dog</TD><TD style="TEXT-ALIGN: center; FONT-FAMILY: Verdana; FONT-SIZE: 10pt">10003</TD><TD style="TEXT-ALIGN: right; BACKGROUND-COLOR: #c0c0c0; FONT-FAMILY: Verdana; FONT-SIZE: 10pt">3245</TD></TR><TR style="HEIGHT: 18px"><TD style="TEXT-ALIGN: center; BACKGROUND-COLOR: #cacaca; FONT-SIZE: 8pt">21</TD><TD style="FONT-FAMILY: Verdana; FONT-SIZE: 10pt">Bird</TD><TD style="TEXT-ALIGN: center; FONT-FAMILY: Verdana; FONT-SIZE: 10pt">10110</TD><TD style="TEXT-ALIGN: right; BACKGROUND-COLOR: #c0c0c0; FONT-FAMILY: Verdana; FONT-SIZE: 10pt">1111</TD><TD style="FONT-FAMILY: Verdana; FONT-SIZE: 10pt">Bull</TD><TD style="TEXT-ALIGN: center; FONT-FAMILY: Verdana; FONT-SIZE: 10pt">18888</TD><TD style="TEXT-ALIGN: right; BACKGROUND-COLOR: #c0c0c0; FONT-FAMILY: Verdana; FONT-SIZE: 10pt">8787</TD></TR><TR style="HEIGHT: 18px"><TD style="TEXT-ALIGN: center; BACKGROUND-COLOR: #cacaca; FONT-SIZE: 8pt">22</TD><TD style="FONT-FAMILY: Verdana; FONT-SIZE: 10pt">Horse</TD><TD style="TEXT-ALIGN: center; FONT-FAMILY: Verdana; FONT-SIZE: 10pt">10118</TD><TD style="TEXT-ALIGN: right; BACKGROUND-COLOR: #c0c0c0; FONT-FAMILY: Verdana; FONT-SIZE: 10pt">3232</TD><TD style="FONT-FAMILY: Verdana; FONT-SIZE: 10pt"> </TD><TD style="FONT-FAMILY: Verdana; FONT-SIZE: 10pt"> </TD><TD style="FONT-FAMILY: Verdana; FONT-SIZE: 10pt"> </TD></TR><TR style="HEIGHT: 18px"><TD style="TEXT-ALIGN: center; BACKGROUND-COLOR: #cacaca; FONT-SIZE: 8pt">23</TD><TD style="FONT-FAMILY: Verdana; FONT-SIZE: 10pt">Dog</TD><TD style="TEXT-ALIGN: center; FONT-FAMILY: Verdana; FONT-SIZE: 10pt">10003</TD><TD style="TEXT-ALIGN: right; BACKGROUND-COLOR: #c0c0c0; FONT-FAMILY: Verdana; FONT-SIZE: 10pt">3245</TD><TD style="FONT-FAMILY: Verdana; FONT-SIZE: 10pt"> </TD><TD style="FONT-FAMILY: Verdana; FONT-SIZE: 10pt"> </TD><TD style="FONT-FAMILY: Verdana; FONT-SIZE: 10pt"> </TD></TR><TR style="HEIGHT: 18px"><TD style="TEXT-ALIGN: center; BACKGROUND-COLOR: #cacaca; FONT-SIZE: 8pt">24</TD><TD style="FONT-FAMILY: Verdana; FONT-SIZE: 10pt">Bull</TD><TD style="TEXT-ALIGN: center; FONT-FAMILY: Verdana; FONT-SIZE: 10pt">18888</TD><TD style="TEXT-ALIGN: right; BACKGROUND-COLOR: #c0c0c0; FONT-FAMILY: Verdana; FONT-SIZE: 10pt">8787</TD><TD style="FONT-FAMILY: Verdana; FONT-SIZE: 10pt"> </TD><TD style="FONT-FAMILY: Verdana; FONT-SIZE: 10pt"> </TD><TD style="FONT-FAMILY: Verdana; FONT-SIZE: 10pt"> </TD></TR><TR style="HEIGHT: 19px"><TD style="TEXT-ALIGN: center; BACKGROUND-COLOR: #cacaca; FONT-SIZE: 8pt">25</TD><TD style="FONT-FAMILY: Verdana; FONT-SIZE: 10pt"> </TD><TD style="FONT-FAMILY: Verdana; FONT-SIZE: 10pt"> </TD><TD style="FONT-FAMILY: Verdana; FONT-SIZE: 10pt"> </TD><TD style="FONT-FAMILY: Verdana; FONT-SIZE: 10pt"> </TD><TD style="FONT-FAMILY: Verdana; FONT-SIZE: 10pt"> </TD><TD style="FONT-FAMILY: Verdana; FONT-SIZE: 10pt"> </TD></TR></TBODY></TABLE>

Excel tables to the web >> http://www.excel-jeanie-html.de/index.php?f=1" target="_blank"> Excel Jeanie HTML 4
 
Upvote 0
Try sticking step -1 on the end of the for

For i = 37 To .Range("B" & .Rows.Count).End(xlUp).Row step -1
so it counts DOWM from 37 to the first in the range
 
Upvote 0
Hi Charles thanks for the suggestion however that did not work. Hyat in sample1 at the end of the macro Post 15 here are the dog that are present on sheet2.

Excel Workbook
BCDEFG
10ITEMACC No.JOB NO. AITEMACC No.JOB NO. A
11Cat100059876Cat100059876
12Dog100031234Dog100031234
13Rat100061234Rat100061234
14Pig100081234Pig100081234
15Rat100061234Dog100039876
16Dog100039876Pig100089876
17Dog100031234Cat100051234
18Pig100089876Dog100036789
19Cat100051234Bird101101111
20Dog100036789Horse101183232
21Bird101101111Dog100033245
22Horse101183232Bull188888787
23Dog100033245
24Bull188888787
25
Sheet2


In the next part on the code a sort is done and only unique records of Job Nos are combined into one Job No column.

However in sample2 as shown previously I do not get the records all the records with the unique Job No. As you can see in Post 17 there is Field Hand Services with a Job No A and a Job No B so that should be shown on sheet2 but it is not.

As you can see no Field Hand Services with Job No 1046 be for the sort takes place.

I do not understand this as it is the same macro used on both work books both have the same sheet names and cell locations the only difference is the data.

Excel Workbook
BCDEFG
10ITEMACC No.JOB NO. AITEMACC No.JOB NO. A
11Field Hand Services9-01202021Field Hand Services9-01202021
12SURVEYS9-04009999SURVEYS9-04009999
13Petty Cash1-11092099Petty Cash1-11092099
14Training/Conferences/Courses9-01251021Training/Conferences/Courses9-01251021
15Drafting & Computing Services9-01151046Drafting & Computing Services9-01151046
16Payroll Recoveries6-10991000Payroll Recoveries6-10991000
17Staff Paye2-21011021Staff Paye2-21011021
18Management Fees4-30002070Management Fees4-30002070
19Management Fees4-30002020Management Fees4-30002020
20Director Fees6-10912047Director Fees6-10912047
21Vehicle Operating Costs9-07602069Vehicle Operating Costs9-07602069
22
23
Sheet2
 
Upvote 0

Forum statistics

Threads
1,224,522
Messages
6,179,297
Members
452,903
Latest member
Knuddeluff

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