Solved

VB Code

Posted on 2011-02-21
4
227 Views
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
0
Comment
Question by:Gazza83
  • 2
  • 2
4 Comments
 
LVL 33

Accepted Solution

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

jppinto
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

FindLastRow.xlsm
0
 
LVL 65

Expert Comment

by:RobSampson
ID: 34947671
Hi there, try this.

Regards,

Rob.
intNextRow = GetNextRow("B")

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

Open in new window

0
 
LVL 65

Expert Comment

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

Expert Comment

by:jppinto
ID: 34947701
LOL...it happens to all sometimes.
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

You need to know the location of the Office templates folder, so that when you create new templates, they are saved to that location, and thus are available for selection when creating new documents.  The steps to find the Templates folder path are …
Access developers frequently have requirements to interact with Excel (import from or output to) in their applications.  You might be able to accomplish this with the TransferSpreadsheet and OutputTo methods, but in this series of articles I will di…
The viewer will learn how to use a discrete random variable to simulate the return on an investment over a period of years, create a Monte Carlo simulation using the discrete random variable, and create a graph to represent the possible returns over…
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.

713 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