Fill down part of macro does not work when only 1 or 2 rows of data

CiaoKarina

New Member
Joined
Oct 22, 2021
Messages
12
Office Version
  1. 365
Platform
  1. MacOS
Hi! I'm sure this is something simple, its just that I am new to macros and don't completely understand everything I've found online!

I have a macro that is working great for me UNLESS I only have 1 or 2 rows of data.
First, let me explain my goal: In this example, Joe Johnson has 2 policies and I need his employee information on every line associated with him, so I need to "fill down" until the next value is found.

1638404237580.png


There are other things happening in the macro, but what I ultimately end up with is new B and C columns. B is concatenating the last 4 of A and the first 2 of what is now D.
Then I am using the "fill down" part of the macro to get a completed column C.


1638404701179.png


The error I get when there are only 1 or 2 rows is "AutoFill method of Range class failed". I can get around this by creating different macros for each but I'd rather understand what I'm doing wrong. There will never be a set number of rows. First time attaching mini-sheets so hopefully doing this correctly!
Thanks!
K



SAMPLEFILE.xlsm
ABCDEFG
1PayorNumberPayor NamePolicy NumberTypeDeduction AmountTotal DueAmount Remitted
2XXXXXX1234SMITH,ELIZABETH1234566GU105.92105.92105.92
3XXXXXX5678JONES,MICHAEL1234567GU110.48110.48110.48
4XXXXXX1111JOHNSON,JOE1234568GU131.18131.18131.18
51234569GU22.4622.4622.46
6TOTAL153.64153.64153.64
7XXXXXX2222ALVAREZ,MARIA876543Cancer24.924.924.9
8XXXXXX3333SIMPSON,JESSE8765432Cancer24.3624.3624.36
Allstate Bill



SAMPLEFILE.xlsm
ABCDEFG
1PayorNumberPayor NamePolicy NumberTypeDeduction AmountTotal DueAmount Remitted
2XXXXXX1234SMITH,ELIZABETH1234566GU105.92105.92105.92
3XXXXXX5678JONES,MICHAEL1234567GU110.48110.48110.48
4
Allstate 2 people



SAMPLEFILE.xlsm
ABCDEFGH
1PayorNumberPayor NamePolicy NumberTypeDeduction AmountTotal DueAmount RemittedReason
2XXXXXX1234SMITH,ELIZABETH1234566GU105.92105.92105.92
3
Allstate 1 person
 

Excel Facts

Which lookup functions find a value equal or greater than the lookup value?
MATCH uses -1 to find larger value (lookup table must be sorted ZA). XLOOKUP uses 1 to find values greater and does not need to be sorted.
It can be solved via simple formula
Book1
ABCDEFGH
1PayorNumberPayor NamePolicy NumberTypeDeduction AmountTotal DueAmount Remitted
2XXXXXX12341234SMSMITH,ELIZABETH1234566GU105.92105.92105.92
3XXXXXX56785678JOJONES,MICHAEL1234567GU110.48110.48110.48
4XXXXXX11111111JOJOHNSON,JOE1234568GU131.18131.18131.18
51111JO1234569GU22.4622.4622.46
61111JOTOTAL153.64153.64153.64
7XXXXXX22222222ALALVAREZ,MARIA876543Cancer24.924.924.9
8XXXXXX33333333SISIMPSON,JESSE8765432Cancer24.3624.3624.36
9
Sheet1
Cell Formulas
RangeFormula
B2:B8B2=RIGHT(LOOKUP(2,1/($A$1:A2<>""),$A$1:A2),4)&LEFT(LOOKUP(2,1/($C$1:C2<>""),$C$1:C2),2)
 
Upvote 0
Thanks! So first, thanks for simplifying my two step process into one! It worked for the sheet with 2 rows and more than 2 but I still get this error on the sheet with only row.

1638410581502.png
 
Upvote 0
Why RC[-1]? in my origin formula, B2 lookup for range A1:A2
May be RC only? try it.
If it does not work, try to show results after coding and hightlight the wrong results.
 
Upvote 0
Honestly, I am not sure. It doesn't seem to be a problem with the formula itself. When I paste your formula into the spreadsheet it works in all 3 sheets. When I record the macro and paste it in, it makes it the RC[-1] (?)
What doesn't work is when I change the fill down range from B2:B8 (which is what is saved in the macro when I double click the corner of B2 to fill down).
Since I will never have a set number of rows I am looking to fill down as long as I have a value in column H.

The results are correct, but it stops the macro.

1638445859637.png
 
Upvote 0
Another question...I created the macros on a MAC version of Excel and this new formula is not working for users I shared it with who are running Windows. It immediately stops and debugger goes to the formula. Any idea what might be different? Thanks!
 
Upvote 0

Forum statistics

Threads
1,214,918
Messages
6,122,255
Members
449,075
Latest member
staticfluids

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