Code frustration...please help

Av8tordude

Well-known Member
Joined
Oct 13, 2007
Messages
1,074
Office Version
  1. 2019
Platform
  1. Windows
Code:
Dim rData As RangeDim Lst As Long, LRow As Long


LRow = Range("W" & Rows.Count).End(xlUp).Row
Range("V18:Y" & LRow).ClearContents


Set rData = Range("A18", Range("B" & Rows.Count).End(xlUp))
rData.AdvancedFilter Action:=xlFilterCopy, CopyToRange:=Range("W18"), Unique:=True


With Range("W18").CurrentRegion
    .Sort Key1:=.Columns(1), Order1:=xlAscending, Header:=xlYes
    .Columns(3).Formula = "=SUMIF(" & rData.Columns(1).Address & ",W18," & rData.Columns(16).Address & ")"
    Range("V18") = 1
    Range("V18").AutoFill Destination:=Range("V18").Resize(LRow), Type:=xlFillSeries
End With


I'm trying to autofill numerical numbers to the last used row in column W, but the autofill fills in an additional 16 numbers past the last row in column W. Please help fix my dilemma

Also I set my table to start from Row 18 and I adjusted this part of the code, but I'm not sure I understand why I can't adjust Range("B" & Rows.Count to reflect it to start from row 18
Code:
Set rData = Range("A18", Range("B" & Rows.Count).End(xlUp))

Thank you kindly
 
Last edited:

Excel Facts

Does the VLOOKUP table have to be sorted?
No! when you are using an exact match, the VLOOKUP table can be in any order. Best-selling items at the top is actually the best.
when you F8 with the code does lastrow change at all
or you do something along these lines
Range("V18").AutoFill Destination:=Range("V18").Resize(LRow), Type:=xlFillSeries
Range("V18").AutoFill Destination:=Range("V18:V" & LRow), Type:=xlFillSeries
 
Upvote 0
when you F8 with the code does lastrow change at all

I'm not sure what you mean, but A18 to lastrow is dynamic so there will be more items added.

or you do something along these lines
Range("V18").AutoFill Destination:=Range("V18").Resize(LRow), Type:=xlFillSeries
Range("V18").AutoFill Destination:=Range("V18:V" & LRow), Type:=xlFillSeries

I'm not sure what you mean by this.
 
Last edited:
Upvote 0
The code seems not consistent or stable... I get this output sometimes..

-16
-15
-14
-13
-12
-11
-10
-9
-8
-7
-6
-5
-4
-3
-2
-1
ItemTickerCompany Amount
1BAThe Boeing Company $ 3,410.26
AAPAdvance Auto Parts $ -
AAPLApple Inc. $ (2,861.56)
ABTAbbott Laboratories $ 1,583.74
ADBEAdobe Inc. $ (4,105.00)

<tbody>
</tbody>


this too...

84WPWorldpay $ 543.20
85WYNNWynn Resorts $ 1,867.40
86XLNXXilinx $ 532.10
87ZZillow $ (141.90)
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104

<colgroup><col span="2"><col><col></colgroup><tbody>
</tbody>
 
Last edited:
Upvote 0
So this >
LRow = Range("W" & Rows.Count).End(xlUp).Row providing W is the Lowest Row should give you an end point

Range("V18").AutoFill Destination:=Range("V18:V" & LRow), Type:=xlFillSeries should fill V down to the LRow Value much like (V18:V45) would
 
Upvote 0
I understand, however its adding an additional 18 numbers with there is nothing past the last row in W
 
Upvote 0
from your original code ? or did you try the change
 
Upvote 0
Perhaps an explanation as to why you are getting an extra 18 rows will help:
Assume the last line with data is row 22
this line:
Code:
LRow = Range("W" & Rows.Count).End(xlUp).Row
will put the number 22 into LRow
this line of code
Code:
Range("V18").AutoFill Destination:=Range("V18").Resize(LRow), Type:=xlFillSeries
says fiill a range starting a V18 and resize by Lrow (which is 22), which put s the end of the range at row 40, i.e. 18 rows beyond where you need it.
 
Last edited:
Upvote 0

Forum statistics

Threads
1,214,912
Messages
6,122,204
Members
449,072
Latest member
DW Draft

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