Home

VBA for autofill

%3CLINGO-SUB%20id%3D%22lingo-sub-886709%22%20slang%3D%22en-US%22%3EVBA%20for%20autofill%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-886709%22%20slang%3D%22en-US%22%3E%3CP%3EHi%20Wizards%2C%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3ELet%20me%20first%20preface%20this%20by%20saying%3B%20I%20know%20nothing%20about%20coding.%20But%20in%20my%20experience%2C%20when%20you%20feel%20there%20can%20be%20a%20more%20efficient%20way%20to%20do%20something%2C%20there%20usually%20is%20one.%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EI%20am%20seeking%20a%20way%20to%20do%20two%20things%3A%3C%2FP%3E%3CP%3E1)%20Populate%20n%20number%20of%20columns%20with%20the%20same%20number.%26nbsp%3B%3C%2FP%3E%3CP%3EEx.%20Populate%20A2%20-%20A16%20with%20the%20number%201.%3C%2FP%3E%3CP%3E2)%20Populate%20n%20number%20of%20columns%20with%20a%20number%20range.%26nbsp%3B%3C%2FP%3E%3CP%3EEx.%20B2%20-%20B16%20with%20numbers%201%20-%2015.%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EI%20work%20with%20arrays%20of%20points%2C%20so%20I%20want%20to%20be%20able%20to%20attribute%20them%20as%20belonging%20to%20column%201%2C%20and%20numbered%20north%20to%20south%20in%20that%20column.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EImagine%20an%20array%20with%2032%20columns%20and%2015%20points%20in%20each...That%20is%20a%20lot%20of%20copying%20and%20pasting.%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EAny%20help%20with%20this%20will%20be%20greatly%20appreciated.%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EThanks%20in%20advance%20%3CLI-EMOJI%20id%3D%22lia_slightly-smiling-face%22%20title%3D%22%3Aslightly_smiling_face%3A%22%3E%3C%2FLI-EMOJI%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EMucho%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-LABS%20id%3D%22lingo-labs-886709%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3EExcel%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E%3CLINGO-SUB%20id%3D%22lingo-sub-887118%22%20slang%3D%22en-US%22%3ERe%3A%20VBA%20for%20autofill%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-887118%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F418152%22%20target%3D%22_blank%22%3E%40Mucho_Elanstrand%3C%2FA%3E%26nbsp%3BHow's%20this%3A%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CPRE%20class%3D%22lia-code-sample%20language-markup%22%3E%3CCODE%3ESub%20BuildArray()%0A%20%20%20%20Dim%20i%20As%20Long%0A%20%20%20%20Dim%20x%20As%20Long%0A%20%20%20%20Dim%20y%20As%20Long%0A%20%20%20%20%0A%20%20%20%20x%20%3D%20Application.InputBox(%22How%20many%20columns%20do%20you%20want%20to%20fill%3F%22%2C%20%22Column%20Count%22%2C%201%2C%20Type%3A%3D1)%0A%20%20%20%20y%20%3D%20Application.InputBox(%22How%20many%20rows%20do%20you%20want%20to%20fill%3F%22%2C%20%22Row%20Count%22%2C%201%2C%20Type%3A%3D1)%0A%20%20%20%20%0A%20%20%20%20Range(%22A2%3AA16%22).Value%20%3D%201%0A%20%20%20%20%0A%20%20%20%20For%20i%20%3D%201%20To%20y%0A%20%20%20%20%20%20%20%20Range(Cells(i%2C%202)%2C%20Cells(i%2C%20x)).Offset(1).Value%20%3D%20i%0A%20%20%20%20Next%20i%0A%20%20%20%20%0AEnd%20Sub%0A%3C%2FCODE%3E%3C%2FPRE%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-887594%22%20slang%3D%22en-US%22%3ERe%3A%20VBA%20for%20autofill%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-887594%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F10827%22%20target%3D%22_blank%22%3E%40Smitty%20Smith%3C%2FA%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EThank%20you%20so%20much!!!%20I'll%20try%20it%20out%20tonight%20and%20let%20you%20know%20how%20it%20goes.%20%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-889418%22%20slang%3D%22en-US%22%3ERe%3A%20VBA%20for%20autofill%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-889418%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F10827%22%20target%3D%22_blank%22%3E%40Smitty%20Smith%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EHi%20Smitty%2C%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EThe%20code%20works!%20However%20I%20need%20a%20little%20modification.%20As%20it%20stands%2C%20it%20populates%20rows%202%20-%2016%20of%20column%20A%20and%20B%20with%20the%20numbers%201-15%20as%20in%20the%20first%20screenshot%20(A).%20What%20I%20need%20however%2C%20is%20what%20it%20looks%20like%20in%20the%20second%20screenshot%20(B).%20How%20would%20I%20accomplish%20that%3F%20%3CLI-EMOJI%20id%3D%22lia_slightly-smiling-face%22%20title%3D%22%3Aslightly_smiling_face%3A%22%3E%3C%2FLI-EMOJI%3E%20Thank%20you%2C%20sensei!%3C%2FP%3E%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-left%22%20style%3D%22width%3A%20206px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Fgxcuf89792.i.lithium.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F135153i23352C749EEDAC5A%2Fimage-size%2Flarge%3Fv%3D1.0%26amp%3Bpx%3D999%22%20alt%3D%22A.PNG%22%20title%3D%22A.PNG%22%20%2F%3E%3CSPAN%20class%3D%22lia-inline-image-caption%22%20onclick%3D%22event.preventDefault()%3B%22%3EA%3C%2FSPAN%3E%3C%2FSPAN%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-left%22%20style%3D%22width%3A%20183px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Fgxcuf89792.i.lithium.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F135154iA1A4CA86F9F3F29D%2Fimage-size%2Flarge%3Fv%3D1.0%26amp%3Bpx%3D999%22%20alt%3D%22B.PNG%22%20title%3D%22B.PNG%22%20%2F%3E%3CSPAN%20class%3D%22lia-inline-image-caption%22%20onclick%3D%22event.preventDefault()%3B%22%3EB%3C%2FSPAN%3E%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CDIV%20class%3D%22mceNonEditable%20lia-copypaste-placeholder%22%3E%26nbsp%3B%3C%2FDIV%3E%3CDIV%20class%3D%22mceNonEditable%20lia-copypaste-placeholder%22%3E%26nbsp%3B%3C%2FDIV%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-889492%22%20slang%3D%22en-US%22%3ERe%3A%20VBA%20for%20autofill%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-889492%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F10827%22%20target%3D%22_blank%22%3E%40Smitty%20Smith%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%3CP%3EFor%20a%20bigger%20picture%2C%20I%20am%20dealing%20with%20points%20that%20exist%20in%20real%20life%20as%20my%20sketch%20below.%26nbsp%3B%3C%2FP%3E%3CP%3ESo%20in%20excel%2C%20i'd%20like%20to%20categorize%20them%20in%20adjacent%20columns%20as%20shown%20in%20the%20excel%20screenshot%20also%20attached.%26nbsp%3B%3C%2FP%3E%3CP%3ECategorizing%20the%20data%20in%20two%20columns%20for%20all%20points%20in%20the%20array.%20If%20we%20can%20pull%20this%20off%20it%20will%20speed%20up%20my%20workflow%20tremendously.%26nbsp%3B%3C%2FP%3E%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20style%3D%22width%3A%20480px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Fgxcuf89792.i.lithium.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F135165i35CF6807341A4685%2Fimage-size%2Flarge%3Fv%3D1.0%26amp%3Bpx%3D999%22%20alt%3D%22array%20skecth.jpg%22%20title%3D%22array%20skecth.jpg%22%20%2F%3E%3C%2FSPAN%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20style%3D%22width%3A%20203px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Fgxcuf89792.i.lithium.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F135168iE6FF27210379F7AC%2Fimage-size%2Flarge%3Fv%3D1.0%26amp%3Bpx%3D999%22%20alt%3D%22C.PNG%22%20title%3D%22C.PNG%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-889639%22%20slang%3D%22en-US%22%3ERe%3A%20VBA%20for%20autofill%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-889639%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F418152%22%20target%3D%22_blank%22%3E%40Mucho_Elanstrand%3C%2FA%3E%26nbsp%3BWith%20the%20code%20I%20posted%2C%20if%20you%20were%20to%20enter%2010%20(columns)%20%26amp%3B%2015%20(rows)%2C%20you'd%20get%20this%3A%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-center%22%20style%3D%22width%3A%20400px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Fgxcuf89792.i.lithium.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F135180iCF4FC017E1374013%2Fimage-size%2Fmedium%3Fv%3D1.0%26amp%3Bpx%3D400%22%20alt%3D%22tmp.jpg%22%20title%3D%22tmp.jpg%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EIsn't%20that%20what%20you%20were%20after%3F%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EAlso%2C%20you%20might%20want%20to%20add%20this%20line%20of%20code%20to%20clear%20out%20any%20previous%20entries%3A%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EActiveSheet.UsedRange.Offset(1).ClearContents%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-889657%22%20slang%3D%22en-US%22%3ERe%3A%20VBA%20for%20autofill%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-889657%22%20slang%3D%22en-US%22%3EOK%2C%20so%20in%20this%20case%20you%20want%20to%20create%20a%20repeating%20array%20based%20on%20the%20lower%2Fupper%20boundaries%20in%20the%20outside%20column%3F%20I%20can%20see%20the%20row%20pattern%20for%20columns%20A%20%26amp%3B%20B%2C%20but%20how%20many%20columns%20should%20be%20created%2C%20and%20do%20they%20follow%20the%20same%20pattern%3F%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-889783%22%20slang%3D%22en-US%22%3ERe%3A%20VBA%20for%20autofill%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-889783%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F10827%22%20target%3D%22_blank%22%3E%40Smitty%20Smith%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EIt%20was%20my%20fault%2C%20I%20realize%20i%20didn't%20explain%20myself%20correctly.%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EI%20want%20to%20keep%20everything%20in%20two%20columns.%20And%20yes%2C%20create%20a%20repeating%20and%20or%20sequencing%20array%20(whichever%20the%20right%20terminology%20is)%20based%20on%20those%20outer%20limits.%20And%2C%20keeping%20the%20data%20in%20those%20two%20columns%20only.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EIn%20the%20screenshot%20attached%20I%20have%20an%20array%20of%2037%20columns%2C%20with%2011%20points%20in%20each.%3C%2FP%3E%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20style%3D%22width%3A%20999px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Fgxcuf89792.i.lithium.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F135190iA1F16E767EE8631A%2Fimage-size%2Flarge%3Fv%3D1.0%26amp%3Bpx%3D999%22%20alt%3D%22Array%20Test.PNG%22%20title%3D%22Array%20Test.PNG%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%3CP%3EIf%20possible%2C%20i'd%20like%20to%20be%20able%20to%20tell%20the%20program%3C%2FP%3E%3CP%3E%26gt%3B%20there%20are%2037%20columns%2C%20and%2011%20points%20in%20each%20(North%20to%20South)%20%26gt%3B%20from%20where%20my%20cursor%20is%2Factive%20cell%2C%20give%20each%20%22point%22%20a%20column%20number%2C%20and%20a%20point%20number%20associated%20with%20that%20column%20%26gt%3B%20stop%20when%20all%20points%20have%20been%20categorized%20(in%20this%20case%20it'll%20be%2037x11%20%3D%20407%20points).%22%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EIf%20my%20cursor%20is%20in%20cell%20A2%2C%20then%20hopefully%20i%20get%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EA2%26nbsp%3B%20%26nbsp%3B%20B2%3C%2FP%3E%3CP%3E1%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B1%3C%2FP%3E%3CP%3E1%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B2%3C%2FP%3E%3CP%3E1%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B3%3C%2FP%3E%3CP%3E1%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B4%3C%2FP%3E%3CP%3E1%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B5%3C%2FP%3E%3CP%3E1%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B6%3C%2FP%3E%3CP%3E1%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B7%3C%2FP%3E%3CP%3E1%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B8%3C%2FP%3E%3CP%3E1%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B9%3C%2FP%3E%3CP%3E1%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%2010%3C%2FP%3E%3CP%3E1%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%2011%3C%2FP%3E%3CP%3E2%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B1%3C%2FP%3E%3CP%3E2%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B2%3C%2FP%3E%3CP%3E2%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B3%3C%2FP%3E%3CP%3E2%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B4%3C%2FP%3E%3CP%3E2%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B5%3C%2FP%3E%3CP%3E2%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B6%3C%2FP%3E%3CP%3E2%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B7%3C%2FP%3E%3CP%3E2%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B8%3C%2FP%3E%3CP%3E2%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B9%3C%2FP%3E%3CP%3E2%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B10%3C%2FP%3E%3CP%3E2%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B11%3C%2FP%3E%3CP%3E3%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B1%3C%2FP%3E%3CP%3E3%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B2%3C%2FP%3E%3CP%3E3%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B3%3C%2FP%3E%3CP%3E3%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B4%3C%2FP%3E%3CP%3E3%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B5%3C%2FP%3E%3CP%3E3%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B6%3C%2FP%3E%3CP%3E3%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B7%3C%2FP%3E%3CP%3E3%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B8%3C%2FP%3E%3CP%3E3%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B9%3C%2FP%3E%3CP%3E3%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%2010%3C%2FP%3E%3CP%3E3%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B11%3C%2FP%3E%3CP%3E.%3C%2FP%3E%3CP%3E.%3C%2FP%3E%3CP%3E.%3C%2FP%3E%3CP%3E.%3C%2FP%3E%3CP%3E37%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B1%3C%2FP%3E%3CP%3E37%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B2%3C%2FP%3E%3CP%3E37%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B3%3C%2FP%3E%3CP%3E37%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B4%3C%2FP%3E%3CP%3E37%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B5%3C%2FP%3E%3CP%3E37%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B6%3C%2FP%3E%3CP%3E37%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B7%3C%2FP%3E%3CP%3E37%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B8%3C%2FP%3E%3CP%3E37%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B9%3C%2FP%3E%3CP%3E37%26nbsp%3B%20%26nbsp%3B%2010%3C%2FP%3E%3CP%3E37%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B11%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-889896%22%20slang%3D%22en-US%22%3ERe%3A%20VBA%20for%20autofill%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-889896%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F418152%22%20target%3D%22_blank%22%3E%40Mucho_Elanstrand%3C%2FA%3E%26nbsp%3BSorry%2C%20I%20can't%20really%20see%20anything%20in%20your%20screen%20shot.%20Can%20you%20save%20a%20copy%20of%20your%20workbook%20to%20OneDrive%20and%20post%20a%20link%20back%20here%3F%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-889939%22%20slang%3D%22en-US%22%3ERe%3A%20VBA%20for%20autofill%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-889939%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F10827%22%20target%3D%22_blank%22%3E%40Smitty%20Smith%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EIt%20was%20just%20a%20screen%20shot%20from%20another%20program%20(AutoCAD)%20showing%20the%20points%20in%20an%20array.%26nbsp%3B%3C%2FP%3E%3CDIV%20class%3D%22mceNonEditable%20lia-copypaste-placeholder%22%3E%26nbsp%3B%3C%2FDIV%3E%3CP%3EI%20attached%20a%20pdf.%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EI%20calculate%20the%20points%20of%20array%20in%20CAD%20as%20shown%20in%20the%20PDF.%20Now%20I%20wan't%20to%20categorize%20them%20as%20explained.%3C%2FP%3E%3CDIV%20class%3D%22mceNonEditable%20lia-copypaste-placeholder%22%3E%26nbsp%3B%3C%2FDIV%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-890002%22%20slang%3D%22en-US%22%3ERe%3A%20VBA%20for%20autofill%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-890002%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F418152%22%20target%3D%22_blank%22%3E%40Mucho_Elanstrand%3C%2FA%3E%26nbsp%3BSee%20if%20this%20does%20what%20you%20want.%20For%20this%2C%20I%20put%20the%20AutoCAD%20array%20in%20a%20sheet%20called%20Array%2C%20and%20the%20results%20in%20a%20sheet%20called%20Results.%20I'm%20attaching%20a%20copy%20as%20well.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CPRE%20class%3D%22lia-code-sample%20language-markup%22%3E%3CCODE%3ESub%20Array2()%0A%20%20%20%20Dim%20lr%20As%20Long%0A%20%20%20%20Dim%20lc%20As%20Long%0A%20%20%20%20Dim%20i%20As%20Long%0A%20%20%20%20Dim%20x%20As%20Long%0A%20%20%20%20Dim%20y%20As%20Long%0A%20%20%20%20Dim%20ws%20As%20Worksheet%0A%20%20%20%20Dim%20ws1%20As%20Worksheet%0A%20%20%20%20%0A%20%20%20%20Set%20ws%20%3D%20Sheets(%22Results%22)%0A%20%20%20%20ws.Range(%22A1%3AB%22%20%26amp%3B%20Cells(Rows.Count%2C%20%22A%22).End(xlUp).Row).ClearContents%0A%20%20%20%20%0A%20%20%20%20Set%20ws1%20%3D%20Sheets(%22Array%22)%0A%20%20%20%20lr%20%3D%20ws1.Cells(Rows.Count%2C%20%22A%22).End(xlUp).Row%0A%20%20%20%20lc%20%3D%20ws1.Cells(1%2C%20Columns.Count).End(xlToLeft).Column%0A%20%20%20%20%0A%20%20%20%20i%20%3D%201%0A%20%20%20%20For%20x%20%3D%201%20To%20lc%0A%20%20%20%20%20%20%20%20For%20y%20%3D%201%20To%20lr%0A%20%20%20%20%20%20%20%20%20%20%20%20ws.Cells(i%2C%20%22A%22).Value%20%3D%20x%0A%20%20%20%20%20%20%20%20%20%20%20%20ws.Cells(i%2C%20%22B%22).Value%20%3D%20y%0A%20%20%20%20%20%20%20%20%20%20%20%20i%20%3D%20i%20%2B%201%0A%20%20%20%20%20%20%20%20Next%20y%0A%20%20%20%20Next%20x%0A%20%20%20%20%20%20%20%20%0AEnd%20Sub%0A%3C%2FCODE%3E%3C%2FPRE%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-890055%22%20slang%3D%22en-US%22%3ERe%3A%20VBA%20for%20autofill%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-890055%22%20slang%3D%22en-US%22%3E%3CP%3EAh%20I%20see!%26nbsp%3B%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F10827%22%20target%3D%22_blank%22%3E%40Smitty%20Smith%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EThis%20is%20brilliant!%20You%20just%20have%20to%20go%20through%20the%20intermediary%20step%20of%20creating%20the%20array%20in%20another%20sheet%20but%20still%20it%20will%20save%20a%20lot%20of%20time%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EThank%20you%20lots!!%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-890073%22%20slang%3D%22en-US%22%3ERe%3A%20VBA%20for%20autofill%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-890073%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F418152%22%20target%3D%22_blank%22%3E%40Mucho_Elanstrand%3C%2FA%3E%26nbsp%3BGlad%20that%20helped.%20The%20code%20can%20be%20amended%20to%20populate%20the%20array%20before%20creating%20the%20results%20if%20you%20want.%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-891374%22%20slang%3D%22en-US%22%3ERe%3A%20VBA%20for%20autofill%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-891374%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F10827%22%20target%3D%22_blank%22%3E%40Smitty%20Smith%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EI%20don't%20know%20how%20I'll%20ever%20be%20able%20to%20show%20my%20gratitude!%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EYes%20that%20will%20be%20great%20if%20we%20can%20we%20amend%20the%20code%20to%20populate%20the%20array%20before%20creating%20the%20results!%20Can%20you%20do%20that%3F%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%22Maybe%20a%20message%20box%20that%20asks%20how%20many%20columns%20in%20the%20array%22%2C%20%22rows%20in%20the%20array%22%20kind%20of%20thing.%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-892299%22%20slang%3D%22en-US%22%3ERe%3A%20VBA%20for%20autofill%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-892299%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F418152%22%20target%3D%22_blank%22%3E%40Mucho_Elanstrand%3C%2FA%3E%26nbsp%3BHere%20you%20go%3A%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CPRE%20class%3D%22lia-code-sample%20language-markup%22%3E%3CCODE%3EOption%20Explicit%0A%0ASub%20BuildAll()%0A%20%20%20%20Call%20BuildArray%0A%20%20%20%20Call%20ReportArray%0AEnd%20Sub%0A%0ASub%20BuildArray()%0A%20%20%20%20Dim%20i%20As%20Long%0A%20%20%20%20Dim%20x%20As%20Long%0A%20%20%20%20Dim%20y%20As%20Long%0A%20%20%20%20Dim%20ws%20As%20Worksheet%0A%20%20%20%20%0A%20%20%20%20Set%20ws%20%3D%20Sheets(%22Array%22)%0A%20%20%20%20x%20%3D%20Application.InputBox(%22How%20many%20columns%20do%20you%20want%20to%20fill%3F%22%2C%20%22Column%20Count%22%2C%201%2C%20Type%3A%3D1)%0A%20%20%20%20y%20%3D%20Application.InputBox(%22How%20many%20rows%20do%20you%20want%20to%20fill%3F%22%2C%20%22Row%20Count%22%2C%201%2C%20Type%3A%3D1)%0A%20%20%20%20%0A%20%20%20%20With%20ws%0A%20%20%20%20%20%20%20%20.Activate%0A%20%20%20%20%20%20%20%20.UsedRange.Offset(1).ClearContents%0A%20%20%20%20%20%20%20%20.Range(%22A2%3AA%22%20%26amp%3B%20y%20%2B%201).Value%20%3D%201%0A%20%20%20%20%0A%20%20%20%20%20%20%20%20For%20i%20%3D%201%20To%20y%0A%20%20%20%20%20%20%20%20%20%20%20%20.Range(Cells(i%2C%202)%2C%20Cells(i%2C%20x)).Offset(1).Value%20%3D%20i%0A%20%20%20%20%20%20%20%20Next%20i%0A%20%20%20%20End%20With%0A%20%20%20%20%0AEnd%20Sub%0A%0ASub%20ReportArray()%0A%20%20%20%20Dim%20lr%20As%20Long%0A%20%20%20%20Dim%20lc%20As%20Long%0A%20%20%20%20Dim%20i%20As%20Long%0A%20%20%20%20Dim%20x%20As%20Long%0A%20%20%20%20Dim%20y%20As%20Long%0A%20%20%20%20Dim%20ws%20As%20Worksheet%0A%20%20%20%20Dim%20ws1%20As%20Worksheet%0A%20%20%20%20%0A%20%20%20%20Set%20ws%20%3D%20Sheets(%22Results%22)%0A%20%20%20%20ws.Range(%22A1%3AB%22%20%26amp%3B%20Cells(Rows.Count%2C%20%22A%22).End(xlUp).Row).ClearContents%0A%20%20%20%20%0A%20%20%20%20Set%20ws1%20%3D%20Sheets(%22Array%22)%0A%20%20%20%20lr%20%3D%20ws1.Cells(Rows.Count%2C%20%22A%22).End(xlUp).Row%20-%201%0A%20%20%20%20lc%20%3D%20ws1.Cells(1%2C%20Columns.Count).End(xlToLeft).Column%0A%20%20%20%20%0A%20%20%20%20i%20%3D%201%0A%20%20%20%20For%20x%20%3D%201%20To%20lc%0A%20%20%20%20%20%20%20%20For%20y%20%3D%201%20To%20lr%0A%20%20%20%20%20%20%20%20%20%20%20%20ws.Cells(i%2C%20%22A%22).Value%20%3D%20x%0A%20%20%20%20%20%20%20%20%20%20%20%20ws.Cells(i%2C%20%22B%22).Value%20%3D%20y%0A%20%20%20%20%20%20%20%20%20%20%20%20i%20%3D%20i%20%2B%201%0A%20%20%20%20%20%20%20%20Next%20y%0A%20%20%20%20Next%20x%0A%20%20%20%20%20%20%20%20%0AEnd%20Sub%3C%2FCODE%3E%3C%2FPRE%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EWorkbook%20is%20attached%20as%20well.%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-897121%22%20slang%3D%22en-US%22%3ERe%3A%20VBA%20for%20autofill%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-897121%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F10827%22%20target%3D%22_blank%22%3E%40Smitty%20Smith%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%3CP%3EYou%2C%20sir%20are%20a%20saint!!!%20Sorry%20for%20the%20late%20reply%2C%20I%20was%20traveling%20on%20Friday.%3C%2FP%3E%3CP%3EThank%20you%20for%20all%20your%20help%20with%20this%20-%20very%20much%20appreciated.%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-897193%22%20slang%3D%22en-US%22%3ERe%3A%20VBA%20for%20autofill%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-897193%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F418152%22%20target%3D%22_blank%22%3E%40Mucho_Elanstrand%3C%2FA%3E%26nbsp%3BGlad%20I%20could%20help%3C%2FP%3E%3C%2FLINGO-BODY%3E
Mucho_Elanstrand
Occasional Contributor

Hi Wizards,

 

Let me first preface this by saying; I know nothing about coding. But in my experience, when you feel there can be a more efficient way to do something, there usually is one. 

 

I am seeking a way to do two things:

1) Populate n number of columns with the same number. 

Ex. Populate A2 - A16 with the number 1.

2) Populate n number of columns with a number range. 

Ex. B2 - B16 with numbers 1 - 15. 

 

I work with arrays of points, so I want to be able to attribute them as belonging to column 1, and numbered north to south in that column.

 

Imagine an array with 32 columns and 15 points in each...That is a lot of copying and pasting. 

 

Any help with this will be greatly appreciated. 

 

Thanks in advance  

 

Mucho 

 

 

16 Replies

@Mucho_Elanstrand How's this:

 

Sub BuildArray()
    Dim i As Long
    Dim x As Long
    Dim y As Long
    
    x = Application.InputBox("How many columns do you want to fill?", "Column Count", 1, Type:=1)
    y = Application.InputBox("How many rows do you want to fill?", "Row Count", 1, Type:=1)
    
    Range("A2:A16").Value = 1
    
    For i = 1 To y
        Range(Cells(i, 2), Cells(i, x)).Offset(1).Value = i
    Next i
    
End Sub

@Smitty Smith

 

Thank you so much!!! I'll try it out tonight and let you know how it goes.  

 

 

@Smitty Smith 

 

Hi Smitty,

 

The code works! However I need a little modification. As it stands, it populates rows 2 - 16 of column A and B with the numbers 1-15 as in the first screenshot (A). What I need however, is what it looks like in the second screenshot (B). How would I accomplish that? Thank you, sensei!

A.PNGAB.PNGB

 

 
 

@Smitty Smith 

For a bigger picture, I am dealing with points that exist in real life as my sketch below. 

So in excel, i'd like to categorize them in adjacent columns as shown in the excel screenshot also attached. 

Categorizing the data in two columns for all points in the array. If we can pull this off it will speed up my workflow tremendously. 

array skecth.jpgC.PNG

@Mucho_Elanstrand With the code I posted, if you were to enter 10 (columns) & 15 (rows), you'd get this:

 

tmp.jpg

 

Isn't that what you were after?

 

Also, you might want to add this line of code to clear out any previous entries:

 

ActiveSheet.UsedRange.Offset(1).ClearContents

OK, so in this case you want to create a repeating array based on the lower/upper boundaries in the outside column? I can see the row pattern for columns A & B, but how many columns should be created, and do they follow the same pattern?

@Smitty Smith 

 

It was my fault, I realize i didn't explain myself correctly. 

 

I want to keep everything in two columns. And yes, create a repeating and or sequencing array (whichever the right terminology is) based on those outer limits. And, keeping the data in those two columns only.

 

In the screenshot attached I have an array of 37 columns, with 11 points in each.

Array Test.PNG

If possible, i'd like to be able to tell the program

> there are 37 columns, and 11 points in each (North to South) > from where my cursor is/active cell, give each "point" a column number, and a point number associated with that column > stop when all points have been categorized (in this case it'll be 37x11 = 407 points)."

 

If my cursor is in cell A2, then hopefully i get

 

A2    B2

1       1

1       2

1       3

1       4

1       5

1       6

1       7

1       8

1       9

1      10

1      11

2       1

2       2

2      3

2       4

2       5

2       6

2       7

2       8

2       9

2       10

2       11

3       1

3       2

3       3

3       4

3       5

3       6

3       7

3       8

3       9

3      10

3       11

.

.

.

.

37     1

37     2

37     3

37     4

37     5

37     6

37     7

37     8

37     9

37    10

37     11

 

@Mucho_Elanstrand Sorry, I can't really see anything in your screen shot. Can you save a copy of your workbook to OneDrive and post a link back here?

@Smitty Smith 

 

It was just a screen shot from another program (AutoCAD) showing the points in an array. 

 

I attached a pdf. 

 

I calculate the points of array in CAD as shown in the PDF. Now I wan't to categorize them as explained.

 

@Mucho_Elanstrand See if this does what you want. For this, I put the AutoCAD array in a sheet called Array, and the results in a sheet called Results. I'm attaching a copy as well.

 

Sub Array2()
    Dim lr As Long
    Dim lc As Long
    Dim i As Long
    Dim x As Long
    Dim y As Long
    Dim ws As Worksheet
    Dim ws1 As Worksheet
    
    Set ws = Sheets("Results")
    ws.Range("A1:B" & Cells(Rows.Count, "A").End(xlUp).Row).ClearContents
    
    Set ws1 = Sheets("Array")
    lr = ws1.Cells(Rows.Count, "A").End(xlUp).Row
    lc = ws1.Cells(1, Columns.Count).End(xlToLeft).Column
    
    i = 1
    For x = 1 To lc
        For y = 1 To lr
            ws.Cells(i, "A").Value = x
            ws.Cells(i, "B").Value = y
            i = i + 1
        Next y
    Next x
        
End Sub

Ah I see! @Smitty Smith 

 

This is brilliant! You just have to go through the intermediary step of creating the array in another sheet but still it will save a lot of time

 

 

Thank you lots!!

@Mucho_Elanstrand Glad that helped. The code can be amended to populate the array before creating the results if you want.

Highlighted

@Smitty Smith 

 

I don't know how I'll ever be able to show my gratitude!

 

Yes that will be great if we can we amend the code to populate the array before creating the results! Can you do that?

 

"Maybe a message box that asks how many columns in the array", "rows in the array" kind of thing. 

 

@Mucho_Elanstrand Here you go:

 

Option Explicit

Sub BuildAll()
    Call BuildArray
    Call ReportArray
End Sub

Sub BuildArray()
    Dim i As Long
    Dim x As Long
    Dim y As Long
    Dim ws As Worksheet
    
    Set ws = Sheets("Array")
    x = Application.InputBox("How many columns do you want to fill?", "Column Count", 1, Type:=1)
    y = Application.InputBox("How many rows do you want to fill?", "Row Count", 1, Type:=1)
    
    With ws
        .Activate
        .UsedRange.Offset(1).ClearContents
        .Range("A2:A" & y + 1).Value = 1
    
        For i = 1 To y
            .Range(Cells(i, 2), Cells(i, x)).Offset(1).Value = i
        Next i
    End With
    
End Sub

Sub ReportArray()
    Dim lr As Long
    Dim lc As Long
    Dim i As Long
    Dim x As Long
    Dim y As Long
    Dim ws As Worksheet
    Dim ws1 As Worksheet
    
    Set ws = Sheets("Results")
    ws.Range("A1:B" & Cells(Rows.Count, "A").End(xlUp).Row).ClearContents
    
    Set ws1 = Sheets("Array")
    lr = ws1.Cells(Rows.Count, "A").End(xlUp).Row - 1
    lc = ws1.Cells(1, Columns.Count).End(xlToLeft).Column
    
    i = 1
    For x = 1 To lc
        For y = 1 To lr
            ws.Cells(i, "A").Value = x
            ws.Cells(i, "B").Value = y
            i = i + 1
        Next y
    Next x
        
End Sub

 

Workbook is attached as well.

@Smitty Smith 

You, sir are a saint!!! Sorry for the late reply, I was traveling on Friday.

Thank you for all your help with this - very much appreciated. 

 

 

@Mucho_Elanstrand Glad I could help

Related Conversations
Stable version of Edge insider browser
HotCakeX in Discussions on
35 Replies
Tabs and Dark Mode
cjc2112 in Discussions on
30 Replies
How to Prevent Teams from Auto-Launch
chenrylee in Microsoft Teams on
29 Replies
flashing a white screen while open new tab
Deleted in Discussions on
14 Replies