Solved

Cannot get macro to auto fill correct number of entries

Posted on 2016-08-19
10
63 Views
Last Modified: 2016-08-19
Hi Experts using Excel 213

i have the following VBA code which to a certain extent works kind of fine....
I am trying to populate a formula is cell B8 down based on the number of entries in column B2 onwards sheet "Unique List" into B8 and fill down...
so if we have a count of 83 in B2:B85 then autofill said formula in cell B8 (inc B8) 83 times..

Sub Autopopulate()
    
    Dim Rng As Long, Rng1 As Range
    
    Application.ScreenUpdating = False
    
        Rng = Sheets("Unique List").Range("B" & Rows.Count).End(xlUp).Row ' the range of entries
            With Sheets("Broker Level")
        .Range("B8:B" & Rng).FillDown ' the range where the formula is in the first cell
    End With
    
    Application.ScreenUpdating = True

End Sub

Open in new window

0
Comment
Question by:route217
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
  • 3
10 Comments
 
LVL 31

Assisted Solution

by:Subodh Tiwari (Neeraj)
Subodh Tiwari (Neeraj) earned 250 total points
ID: 41762290
Does this work for you?

Sub Autopopulate()
Dim Rng As Range
Application.ScreenUpdating = False
Set Rng = Range("B8:B" & Range("B2").Value)
Range("B8").AutoFill Rng, xlFillDefault
Application.ScreenUpdating = True
End Sub

Open in new window

0
 

Author Comment

by:route217
ID: 41762316
lets give it a try
0
 

Author Comment

by:route217
ID: 41762319
sorry no...

because as per original code b is in sheet unique and populate into worksheet Broker Level...hmm

appreciate the feedback
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:route217
ID: 41762350
ok i see where the error is.....but not sure how to correct it..

If you change to . Range("A2:A" & Rng).Filldown works fine.....
but my starting point is offset to B8...
0
 
LVL 31

Expert Comment

by:Subodh Tiwari (Neeraj)
ID: 41762355
In that case qualify the Range("B2").Value with the sheet reference....

Like this...
Sheets("Unique").Range("B2").Value

Rng in your original code is a Long variable while Rng in the code I suggested it's a Range variable.
0
 
LVL 18

Accepted Solution

by:
xtermie earned 250 total points
ID: 41762364
Try this
Sub Autopopulate2()
   
    Dim Rng As Long, Rng1 As Range
   
    Application.ScreenUpdating = False
   
        Rng = Sheets("Unique List").Range("B" & Rows.Count).End(xlUp).Row ' the range of entries
        Rng = Rng + 8
            With Sheets("Broker Level")
        .Range("B8:B" & Rng).FillDown ' the range where the formula is in the first cell
    End With
   
    Application.ScreenUpdating = True

End Sub
0
 
LVL 18

Expert Comment

by:xtermie
ID: 41762369
you are using the count of the Unique List as the ending part of the Range in the Broker level range
So for example if there are 83 entries in Unique list (Rng = 83) then your fill down area (range) in Broker Level is B8:B83 which is not what you want.

You want B8 +83 rows down, correct?
Which is B8:B91 (that's why I plus 8 your range)
0
 

Author Comment

by:route217
ID: 41762377
Thank u and thank u again..experts
1
 
LVL 31

Expert Comment

by:Subodh Tiwari (Neeraj)
ID: 41762378
You're welcome..
0
 
LVL 18

Expert Comment

by:xtermie
ID: 41762379
glad we could help
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction This Article briefly covers methods of calculating the NPV and IRR variants in Excel as well as the limitations in calculating and interpreting IRR results. Paraphrasing Richard Shockley, author of my favourite finance reference tex…
You need to know the location of the Office templates folder, so that when you create new templates, they are saved to that location, and thus are available for selection when creating new documents.  The steps to find the Templates folder path are …
This Micro Tutorial will demonstrate on a Mac how to change the sort order for chart legend values and decrpyt the intimidating chart menu.
This Micro Tutorial will demonstrate how to use a scrolling table in Microsoft Excel using the INDEX function.

688 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question