VB Code

Posted on 2011-02-21
Last Modified: 2012-05-11
Please can you help, I would like a command button that can find the last value within Column B (B14 downwards)

So if there was text in B14,15,16,17 the command button would select B18

If there was no text in any of the columns from B14 down... then B14 would be selected
Question by:Gazza83
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
LVL 33

Accepted Solution

jppinto earned 500 total points
ID: 34947440
Attached you can find an working example with the code below.

Sub find_last()
Dim lstRow As Long
   lstRow = Sheets("Sheet1").Cells(ActiveSheet.Rows.Count, "B").End(xlUp).Row
   ActiveSheet.Cells(lstRow, 2).Select
End Sub

Open in new window

LVL 65

Expert Comment

ID: 34947671
Hi there, try this.


intNextRow = GetNextRow("B")

Sub GetNextRow(strColumn As String)
	intRow = ActiveSheet.Cells(65536, strColumn).End(xlUp).Row
	If intRow < 14 Then
		intRow = 14
		intRow = intRow + 1
	End If
	GetNextRow = intRow
End Sub

Open in new window

LVL 65

Expert Comment

ID: 34947676
Yikes, didn't refresh for almost an hour...
LVL 33

Expert Comment

ID: 34947701 happens to all sometimes.

Featured Post

Salesforce Made Easy to Use

On-screen guidance at the moment of need enables you & your employees to focus on the core, you can now boost your adoption rates swiftly and simply with one easy tool.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
This code takes an Excel list of URL’s and adds a header titled “URL List”. It then searches through all URL’s in column “A”, looking for duplicates. When a duplicate is found, it is moved to the top of the list. The duplicate URL’s are then highlig…
This Micro Tutorial demonstrates in Microsoft Excel how to consolidate your marketing data by creating an interactive charts using form controls. This creates cool drop-downs for viewers of your chart to choose from.
Many functions in Excel can make decisions. The most simple of these is the IF function: it returns a value depending on whether a condition you describe is true or false. Once you get the hang of using the IF function, you will find it easier to us…

718 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question