vba fill down bottom
The UK's Number 1 for Microsoft Office Training Add this page to your favourites/bookmarksBookmark page
 
View printable version of pagePrintable version
Plus One Google
Customer: Sign in
Delegate: Sign in
Trainer: Log in

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

resolvedResolved · Medium Priority · Version 2007

replyReply Thu 2 Feb 2012, 17:48Delegate Ryan said...

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

For upcoming training course dates see: Pricing & availability

replyReply Fri 3 Feb 2012, 19:16Trainer Anthony said...

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

 

Please browse our web site to find out more about
advanced excel seminar training and other Microsoft training courses.

Excel tip:

Page Break Preview in Excel 2010

If you select View then Workbook Views then Page Break Preview, you will be able to view how your Excel spreadsheet will be split across multiple pages when printed. Even better, you can also drag a page break to a new place. Excel will then scale down your entire worksheet to fit the information you want on the pages you want.

View all Excel hints and tips


Microsoft Certified Partner Accredited Training Provider: Institute of IT Training Institute of Leadership and Management - Certified Courses Security Seal verified by visa, mastercard securecard