Wrox Programmer Forums
|
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 software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old February 3rd, 2005, 12:33 PM
Authorized User
 
Join Date: Dec 2004
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
 
Old February 3rd, 2005, 01:19 PM
Friend of Wrox
 
Join Date: Jun 2003
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
 
Old February 4th, 2005, 05:37 AM
Authorized User
 
Join Date: Dec 2004
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
 
Old February 4th, 2005, 12:37 PM
Friend of Wrox
 
Join Date: Jun 2003
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!
 
Old February 7th, 2005, 01:04 PM
Authorized User
 
Join Date: Dec 2004
Posts: 43
Thanks: 0
Thanked 0 Times in 0 Posts
Default

thats great...thanks a lot Birger

Cheers
Tony
 
Old February 9th, 2005, 03:27 PM
Authorized User
 
Join Date: Sep 2004
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





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





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