Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

VB Code

Posted on 2011-02-21
4
Medium Priority
?
231 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
[X]
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
4 Comments
 
LVL 33

Accepted Solution

by:
jppinto earned 2000 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

Tech or Treat!

Submit an article about your scariest tech experience—and the solution—and you’ll be automatically entered to win one of 4 fantastic tech gadgets.

Question has a verified solution.

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

If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
This article describes a serious pitfall that can happen when deleting shapes using VBA.
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 will demonstrate how to create pivot charts out of a data set. I also added a drop-down menu which allows to choose from different categories in the data set and the chart will automatically update.

604 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