Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Microsoft Office > Excel VBA > Excel VBA
Password Reminder
Register
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
Excel VBA Discuss using VBA for Excel programming.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Excel VBA section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old February 3rd, 2005, 12:33 PM
Authorized User
 
Join Date: Dec 2004
Location: Belfast, Antrim, United Kingdom.
Posts: 43
Thanks: 0
Thanked 0 Times in 0 Posts
Default Comparing 2 cols.

Hi

I have a spreadsheet where I need to loop through a colomn and say say for example compare a string in cell f2 with a string in f3. If the string remains the same the numeric value in cell e2 remains the same but if the string changes, I need to add 5 to the numeric value in e2


Cheers
Tony
__________________
Cheers
Tony
Reply With Quote
  #2 (permalink)  
Old February 3rd, 2005, 01:19 PM
Friend of Wrox
 
Join Date: Jun 2003
Location: , , Denmark.
Posts: 150
Thanks: 0
Thanked 0 Times in 0 Posts
Default

What do you mean with 'remains the same' and 'changes'? You don't mention anything about changing the cellvalues in f2/f3, you're asking how to compare those cells and from that maybe change the value in e2
Reply With Quote
  #3 (permalink)  
Old February 4th, 2005, 05:37 AM
Authorized User
 
Join Date: Dec 2004
Location: Belfast, Antrim, United Kingdom.
Posts: 43
Thanks: 0
Thanked 0 Times in 0 Posts
Default

for instance:
  E F
P2_1000 DEMAND DEPOSITS
P2_1000 DEMAND DEPOSITS
P2_1005 DEMAND DEPOSITS
P2_1010 INSTANT SAVER PLUSP2_1005


Every time the string value of col F changes I need to add 5
to the value in the cell opposite in col e


Cheers
Tony
Reply With Quote
  #4 (permalink)  
Old February 4th, 2005, 12:37 PM
Friend of Wrox
 
Join Date: Jun 2003
Location: , , Denmark.
Posts: 150
Thanks: 0
Thanked 0 Times in 0 Posts
Default

You don't say anything about how you determine whether a cell value has changed or if it matters what it has been changed to and from. Do you compare with another value?

If it doesn't matter, try to place this code in the sheet (not in a module):

Option Explicit
Dim o As Integer

Private Sub Worksheet_Change(ByVal Target As Range)
Dim s As String

    If ActiveCell.Column = 6 Then
        Cells(o, 5).Select
        s = Int(Right(ActiveCell.Value, 4)) + 5
        Cells(o, 5).Value = "P2_" & s
    End If

End Sub


' Don't place this code in the _Change event
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
    o = ActiveCell.Row
End Sub

Let me know if you can't use this!
Reply With Quote
  #5 (permalink)  
Old February 7th, 2005, 01:04 PM
Authorized User
 
Join Date: Dec 2004
Location: Belfast, Antrim, United Kingdom.
Posts: 43
Thanks: 0
Thanked 0 Times in 0 Posts
Default

thats great...thanks a lot Birger

Cheers
Tony
Reply With Quote
  #6 (permalink)  
Old February 9th, 2005, 03:27 PM
Authorized User
 
Join Date: Sep 2004
Location: , , .
Posts: 18
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Tony –

Did you try this?

        Set I to the row where you start the comparison


    Do until I > Num_Of_Rows_for_Comparison
           If .Cells(I, 6).Value <> .cells(I + 1, 6).Value Then
          .Cells(I, 5).value = .Cells(I, 5).Value + 5
           End If
           I = I + 1
        Loop

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
iterating through cols. of a recordset amit_p_patel VB How-To 3 May 24th, 2007 03:41 AM
new table cols per record, paging, & select scottiegirl PHP Databases 5 June 21st, 2006 12:29 PM
Rows and Cols Stuff : MSHFlexGrid davekrunal46 VB How-To 1 December 2nd, 2005 01:21 AM
How to add 2 cols in DataGrid1.DataKeyField drasko ADO.NET 8 May 4th, 2005 02:09 AM
Looking for Datagrid Cols&Columns reyboy Pro VB.NET 2002/2003 1 May 25th, 2004 08:12 AM



All times are GMT -4. The time now is 10:56 AM.


Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.