If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > PC based Database Applications > Microsoft Excel > Select row dependant on column value?

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 01-20-09, 08:36
freeBatjko freeBatjko is offline
Registered User
 
Join Date: Mar 2008
Posts: 89
Select row dependant on column value?

Hi there,

I just started VBA today, for the single purpose to make my life easier with the massive Excel spreadsheets I need to format all the time.

Therefore, question:
How can I select (and then make bold) an entire row, if one value in a specific column equals a certain predefined value?

So something like this (pseudo alert):

Code:
Columns("I:I").Select
If Selection.Value <> "NONE" Then
  EntireRow.Font.Bold = True
End if
But it doesn't work, because (I assume) I need to loop through all rows manually and select each cell in "I:I" before I can do anything with that row?
__________________
"My brain is just no good at being a relational Database - my relations suck real bad!"
Reply With Quote
  #2 (permalink)  
Old 01-20-09, 11:11
freeBatjko freeBatjko is offline
Registered User
 
Join Date: Mar 2008
Posts: 89
Ok, what I have so far looks like this:

Code:
Dim i As Long
       
    Columns("I:I").Select
    
   With Selection
      For i = 2 To Cells.Find(What:="*", After:=Range("I1"), LookIn:=xlValues,  LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row Step 1
        'On Error Resume Next
        If Cells(i, 9).Value <> "NONE" Then
           ActiveSheet.UsedRange.Rows(i).Font.Bold = True
        End If
      Next i
    End With
But it looks crazy and like bad code, and worst of all... it doesn't work.
__________________
"My brain is just no good at being a relational Database - my relations suck real bad!"
Reply With Quote
  #3 (permalink)  
Old 01-20-09, 11:56
freeBatjko freeBatjko is offline
Registered User
 
Join Date: Mar 2008
Posts: 89
Ok, I got it myself actually.

I picked up another idea and ended up doing it this way:

Code:
Selection.AutoFilter Field:=9, Criteria1:="<>NONE"
  Cells.Select
  Range("K9").Activate
  Selection.Font.Bold = True
Range("I2631").Select
Selection.AutoFilter Field:=9, Criteria1:="*"
Thanks for... well providing the crying shoulder.
__________________
"My brain is just no good at being a relational Database - my relations suck real bad!"
Reply With Quote
  #4 (permalink)  
Old 01-23-09, 17:17
loquin loquin is offline
Super Moderator
 
Join Date: Jun 2004
Location: Arizona, USA
Posts: 1,797
Since this issue appears to be much more appropriate to the Excel forum than it does to VB, I'm moving to the Excel forum...
__________________
Lou
使大吃一惊
"Lisa, in this house, we obey the laws of thermodynamics!" - Homer Simpson
"I have my standards. They may be low, but I have them!" - Bette Middler
"It's a book about a Spanish guy named Manual. You should read it." - Dilbert

Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On