Auto-Fill values

Saher Naji

Board Regular
Joined
Dec 19, 2019
Messages
76
Office Version
  1. 2013
Platform
  1. Windows
Hello

Thanks in advance,

I tried to crate a formula, but the problem I have to make the formulas fixed by $ symbol, this will cost me a long time

What I'm looking for is a formula or a macro to do this thing automatically each time, because I have hundreds of rows, and the number of boxes (columns) is not fixed, some times I have 50 boxes or more.

Check the attached screenshot please,

Best.
 

Attachments

  • Screenshot.png
    Screenshot.png
    56.1 KB · Views: 13
Ok. Got it now. Thanks for being clear.

VBA Code:
Sub Boxes()
    Dim lr As Long, lc As Long
    Application.ScreenUpdating = False
    lr = Range("J" & Rows.Count).End(xlUp).Row
    Dim i As Long
    For i = 2 To lr
        lc = Cells(4, Columns.Count).End(xlToLeft).Column
        Range(Cells(i, 14), Cells(i, lc)).Value = Range("J" & i)
    Next i
    Application.ScreenUpdating = True
End Sub

Create a Personal.xlsb file and store this in that file. Google Ron deBruin Personal.xlsb and follow his instructions for creating and using in multiple files.
Perfect, but I want to keep the headers as they are, just I want to repeat the values

Sample File Excel-formula included.xlsx
NOPQRSTUVWXYZAA
4Units per CaseUnits per CaseUnits per CaseUnits per CaseUnits per CaseUnits per CaseUnits per CaseUnits per CaseUnits per CaseUnits per CaseUnits per CaseUnits per CaseUnits per CaseUnits per Case
533003300330033003300330033003300330033003300330033003300
6155155155155155155155155155155155155155155
740004000400040004000400040004000400040004000400040004000
8999999999999999999999999999999999999999999
9300300300300300300300300300300300300300300
1044454445444544454445444544454445444544454445444544454445
1123232323232323232323232323232323232323232323232323232323
12234324234324234324234324234324234324234324234324234324234324234324234324234324234324
Tabelle1
Cells with Conditional Formatting
CellConditionCell FormatStop If True
N16:CG984,O5:CG15Expression=OR(AND(NOT(ISNUMBER(N5)), NOT(ISBLANK(N5))), (N5 < 0))textNO
N16:CG984,O5:CG15Expression=(INT(N5) <> N5)textNO
Cells with Data Validation
CellAllowCriteria
O5:AA12Whole number>=0
 
Upvote 0

Excel Facts

Wildcard in VLOOKUP
Use =VLOOKUP("Apple*" to find apple, Apple, or applesauce
Sorry, did not change this line of code

VBA Code:
For i = 2 To lr

change to

VBA Code:
For i = 5 To lr
 
Upvote 0
Working 100%., thank you very much,
Super
now I'm going to Google Ron deBruin Personal.xlsb and follow his instructions for creating and using in multiple files. ♥
 
Upvote 0
Sample File Excel_corrected.xlsx
HIJKLMNOPQRSTUVWXYZAAABACADAEAF
1
2
3
4Who will label?Expected QTYUnits per CaseNumber of CasesBoxed Case QTYBox 1 - Case QTYBox 2 - Case QTYBox 3 - Case QTYBox 4 - Case QTYBox 5 - Case QTYBox 6 - Case QTYBox 7 - Case QTYBox 8 - Case QTYBox 9 - Case QTYBox 10 - Case QTYBox 11 - Case QTYBox 12 - Case QTYBox 13 - Case QTYBox 14 - Case QTYBox 15 - Case QTYBox 16 - Case QTYBox 17 - Case QTYBox 18 - Case QTYBox 19 - Case QTY
5None Required1105501010101010
6None Required11546015151515
7None Required1201020020202020202020202020
8
9
10
11
Tabelle1
Cell Formulas
RangeFormula
L5:L7L5=SUM(N5:AG5)
Cells with Conditional Formatting
CellConditionCell FormatStop If True
L5:L7Expression=ISERROR(L5)textNO
L5:L7Expression=OR((L5 <> K5), (INT(L5) <> L5))textNO
N5:AG7Expression=OR(AND(NOT(ISNUMBER(N5)), NOT(ISBLANK(N5))), (N5 < 0))textNO
N5:AG7Expression=(INT(N5) <> N5)textNO
Cells with Data Validation
CellAllowCriteria
N5:AF7Whole number>=0



Hello,

in fact your solution was excellent, but there is a wrong in my explanation, it's really my mistake and I'm sorry for that
actually I need the values repeated according to a specific criteria,
The code you created is true, but I need to edit it to be fit with the column K, so if I have 5 cases in column K, this mean it supposed to repeat the Units Value (J) 5 times, then in the second row, if the value (number of cases) in column (K)=4, is supposed to repeat the value 4 times but after the repeated values for the previous row

I hope that my point is clear

Thanks a lot
 
Upvote 0
Try this:
VBA Code:
Option Explicit

Sub Boxes()
    Dim lr As Long, lc As Long, x As Long
    Application.ScreenUpdating = False
    lr = Range("J" & Rows.Count).End(xlUp).Row
    Dim i As Long
    For i = 5 To lr
        x = Range("K" & i) - 1
        lc = Cells(4, Columns.Count).End(xlToLeft).Column
        Range(Cells(i, 14), Cells(i, 14 + x)).Value = Range("J" & i)
    Next i
    Application.ScreenUpdating = True
End Sub

Book1
GHIJKLMNOPQRSTUVW
4Prep TypeWho will label?Expected QTYUnits per CaseNumber of CasesBoxed Case QTYBox 1 - Case QTYBox 2 - Case QTYBox 3 - Case QTYBox 4 - Case QTYBox 5 - Case QTYBox 6 - Case QTYBox 7 - Case QTYBox 8 - Case QTYBox 9 - Case QTYBox 10 - Case QTY
5--None Required13300133003300
6--None Required11552310155155
7--None Required14000312000400040004000
8--None Required199943996999999999999
9--None Required130051500300300300300300
10--None Required14445626670444544454445444544454445
11--None Required123237162612323232323232323232323232323
12--None Required123432481874592234324234324234324234324234324234324234324234324
Sheet1
Cell Formulas
RangeFormula
L5:L12L5=SUM(N5:AG5)
 
Upvote 0
Great and very close to the goal, but could we edit it to start each case after the previous one is done, if you notice the example I sent, Please check this XL2BB


Sample File Excel_corrected.xlsx
JKLMNOPQRSTUVWXYZ
1
2
3
4Units per CaseNumber of CasesBoxed Case QTYBox 1 - Case QTYBox 2 - Case QTYBox 3 - Case QTYBox 4 - Case QTYBox 5 - Case QTYBox 6 - Case QTYBox 7 - Case QTYBox 8 - Case QTYBox 9 - Case QTYBox 10 - Case QTYBox 11 - Case QTYBox 12 - Case QTYBox 13 - Case QTY
5105501010101010
61546015151515
7201018020202020
8
9
10
11
12
13
Tabelle1
Cell Formulas
RangeFormula
L5:L7L5=SUM(N5:AG5)
Cells with Conditional Formatting
CellConditionCell FormatStop If True
L5:L7Expression=ISERROR(L5)textNO
L5:L7Expression=OR((L5 <> K5), (INT(L5) <> L5))textNO
AG7,N7:AE7,N5:AG6Expression=OR(AND(NOT(ISNUMBER(N5)), NOT(ISBLANK(N5))), (N5 < 0))textNO
AG7,N7:AE7,N5:AG6Expression=(INT(N5) <> N5)textNO
Cells with Data Validation
CellAllowCriteria
N5:Z7Whole number>=0
 
Upvote 0
Need to think about this a bit. It is not intuitive to me. Issue with the last column. Will the last column always be the same? What happens when you reach the last column and there are still lines of data to be accounted for? In your example you have 10 columns of cases. Tell us more.
 
Upvote 0
for example if I have 1 case in the 1st row, 2 cases in the 2nd row, and 3 cases in the 3rd row (like the example you sent) this mean 6 cases in total, and this mean I need 6 boxes, and this exactly equal the number of required columns. one column for the first case (Box 1 - Case QTY), 2 columns next to the first column for the the second case because it's (2), and 3 columns next the the previous cases's columns for the 3rd case because the value there is 3.

in other words, the sum of values in column for example Sum(O:O) should equal (10) in this case, and it suppose to be just one number in this column

if you asking about the headers don't worry about this because each time I receive this sheet I receive it edited depending on the number of cases, suppose that I will got 225 cases today, this mean I will receive a new sheet with 225 empty columns from [Box 1 - Case QTY] to [Box 225 - Case QTY], only the headers are there without values.

I thank you from my heart for the great help
 
Upvote 0
Here is a revised code.

VBA Code:
Option Explicit

Sub Boxes()
    Dim lr As Long, lc As Long, x As Long, y As Long
    Application.ScreenUpdating = False
    lr = Range("J" & Rows.Count).End(xlUp).Row
    Dim i As Long
    y = 14
    For i = 5 To lr
        x = Range("K" & i) - 1
        lc = Cells(4, Columns.Count).End(xlToLeft).Column
        Range(Cells(i, y), Cells(i, y + x)).Value = Range("J" & i)
        y = y + x + 1
    Next i
    Application.ScreenUpdating = True
End Sub
 
Upvote 0
Thank you very much, it's perfect(y)(y), is there a way to pay to you, or at least rate you here in this Forums?
 
Upvote 0

Forum statistics

Threads
1,224,820
Messages
6,181,162
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