Go Back  Xtreme Visual Basic Talk > Legacy Visual Basic (VB 4/5/6) > VBA / Office Integration > Excel > How to select current row in Excel


Reply
 
Thread Tools Display Modes
  #1  
Old 02-27-2004, 02:57 PM
tab tab is offline
Newcomer
 
Join Date: Feb 2004
Posts: 1
Default How to select current row in Excel


I've just got into using VB in Excel in the last few days. I learn mostly by recording macros and playing with them and using help.

Anyways, I just need to know how to select the current row so that I can search for something only within that row.

Its probably a very basic task, but thanks for your help.
tab
Reply With Quote
  #2  
Old 02-28-2004, 05:25 AM
herilane's Avatar
herilane herilane is offline
Unashamed geek

Retired Moderator
* Expert *
 
Join Date: Jul 2003
Location: London, England
Posts: 8,988
Default

What are you trying to do? You don't need to select a row in order to refer to it in code.
Reply With Quote
  #3  
Old 02-28-2004, 05:39 AM
italkid's Avatar
italkid italkid is offline
Down...

Retired Moderator
* Expert *
 
Join Date: Dec 2002
Location: Belgium.
Posts: 6,731
Default

Could :
Code:
ActiveCell.Row 'or ActiveCell.EntireRow
be of any use...?
Reply With Quote
  #4  
Old 02-28-2004, 07:17 AM
XL-Dennis XL-Dennis is offline
Banned
 
Join Date: Mar 2003
Location: Ístersund Sweden
Posts: 908
Default

There are certains good coding-practice that the macro-recorder don┤t take into consideration which also imply that You should only use it if You need to find out more about specific objects, properties and methods.

Below You find a example and You should always make sure that You use vriables and explicit declare all the variables. In that way You also avoid to increase the number of dots when working with the objects and so on. In that way the impact of the performance will increase.

As herilane pointed out: There is no need to select the objects we would like to work with.

Personally I prefer, at least in public forums like Extrema, to use the hierarchy of the objects in use. In that way we can also achieve a better understanding of the structure and how objects are related to each others.

Code:
Option Explicit Sub No_Selection_Explicit_Declaration_Variables() Dim wbBook As Workbook Dim wsSheet As Worksheet Dim rnCheck As Range, rnFind As Range Dim stAddress As String Set wbBook = ActiveWorkbook Set wsSheet = wbBook.ActiveSheet With wsSheet Set rnCheck = .Range("1:1") End With With rnCheck Set rnFind = .Find(What:="XL-Dennis", LookIn:=xlValues, lookat:=xlWhole) If Not rnFind Is Nothing Then stAddress = rnFind.Address Do rnFind.Font.Bold = True Set rnFind = .FindNext(rnFind) Loop While Not rnFind Is Nothing And rnFind.Address <> stAddress End If End With End Sub

Good luck with Your coding!

Dennis
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Automating Excel from VB 6.0 Mike Rosenblum Tutors' Corner 7 04-10-2009 07:25 AM
Print Preview rufen101 General 6 10-10-2003 10:45 AM
Pause VB to select a cell in Excel. rpoy Excel 4 09-22-2003 10:20 AM
Trying to execute Select query in Excel using VB 6.0 shiv_379 Word, PowerPoint, Outlook, and Other Office Products 3 07-23-2003 01:39 AM
Excel VBA Select Case vs If Staements I need some big time help :) samst Word, PowerPoint, Outlook, and Other Office Products 6 02-14-2003 09:51 AM

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
 
 
-->