Find the first available cell

Eraengineer

Board Regular
Joined
Jun 12, 2011
Messages
226
I'm looking for a macro that when I type in a number it places it in the first available cell in a range of cells. The range is C2:Z6. I need the number to be placed in C6 first, then C5 then C4, then C3, then C2, and then move to D6, then to D5, etc. Once range C2:Z6 has been filled the next availbe range will be C11:Z15. The same pattern must occur for range C11:Z15. I just need an example to get started. I am entering the number in a textbox on a form.
 

Excel Facts

Convert text numbers to real numbers
Select a column containing text numbers. Press Alt+D E F to quickly convert text to numbers. Faster than "Convert to Number"
Try this:-
Code:
Private [COLOR=navy]Sub[/COLOR] TextBox1_LostFocus()
[COLOR=navy]Dim[/COLOR] Rng [COLOR=navy]As[/COLOR] Range, Dn [COLOR=navy]As[/COLOR] Range, n [COLOR=navy]As[/COLOR] [COLOR=navy]Integer[/COLOR]
[COLOR=navy]Set[/COLOR] Rng = Range("c2: z2")
[COLOR=navy]For[/COLOR] [COLOR=navy]Each[/COLOR] Dn [COLOR=navy]In[/COLOR] Rng
    [COLOR=navy]For[/COLOR] n = 5 To 1 [COLOR=navy]Step[/COLOR] -1
        [COLOR=navy]If[/COLOR] Dn(n) = "" [COLOR=navy]Then[/COLOR]
            Dn(n) = TextBox1.Value
            [COLOR=navy]Exit[/COLOR] [COLOR=navy]Sub[/COLOR]
        [COLOR=navy]End[/COLOR] If
    [COLOR=navy]Next[/COLOR] n
[COLOR=navy]Next[/COLOR] Dn
[COLOR=navy]End[/COLOR] [COLOR=navy]Sub[/COLOR]
Regards Mick
 
Upvote 0

Forum statistics

Threads
1,224,587
Messages
6,179,740
Members
452,940
Latest member
rootytrip

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