Public Schedule Face-to-Face & Online Instructor-Led Training - View dates & book

vba fill down bottom

Forum home » Delegate support and help forum » Microsoft Excel VBA Training and help » VBA to fill down to bottom of table with condition

VBA to fill down to bottom of table with condition

ResolvedVersion 2007

Ryan has attended:
Excel Advanced course
Excel VBA Intro Intermediate course

VBA to fill down to bottom of table with condition

Good afternoon,

Please can you help me?

I am trying to write a piece of code that will number each row in my spreadsheet with an ascending order in column A (ie 1,2,3...), but based on 2 conditions. "the value of column j of that row does not = 0 and there is no value already entered in column A. Where either of these conditions are not met, the code simply moves to the next row. The process needs to repeat until the bottom of the table is reached and then stop.

Unfortunately, I am having great trouble both with the if statement and also in getting the code to continue only to the bottom of the data.

Kind thanks,

Ryan

RE: VBA to fill down to bottom of table with condition

Hi Ryan, thanks for your query. You may have to tweak the criteria on this but the code will look something like this:

------------------

Option Explicit

Sub test()

Dim numberofrows As Integer
Dim introw As Integer
Dim numberlabel As Integer

numberlabel = 1

numberofrows = Sheets("MyData").Range("j1").CurrentRegion.Rows.Count

For introw = 1 To numberofrows

If Sheets("MyData").Range("a1").Cells(introw, 1).Value = "" Then

If Sheets("MyData").Range("j1").Cells(introw, 1).Value <> 0 Then

Sheets("MyData").Range("a1").Cells(introw, 1).Value = numberlabel
numberlabel = numberlabel + 1


End If


End If


Next introw


End Sub


------------------

Hope this helps,

Anthony

 

Training courses

Training information:

Welcome. Please choose your application (eg. Excel) and then post your question.

Our Microsoft Qualified trainers will then respond within 24 hours (working days).

Frequently Asked Questions
What does 'Resolved' mean?

Any suggestions, questions or comments? Please post in the Improve the forum thread.

Excel tip:

Adding up rows or columns without seeing formulas

Highlight a column or row and click the Autosum button. This gives you your answer without showing the formula.

View all Excel hints and tips

Connect with us:

0207 987 3777

Call for assistance

Request Callback

We will call you back

Server loaded in 0.09 secs.