Welcome to the Excel Forum

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.

Please Register to Remove these Ads

Please Register to Remove these Ads



Reply
  #1  
Old 07-04-2009, 08:00 PM
CF250 CF250 is offline
Registered User
 
Join Date: 04 Jul 2009
Location: London, England
MS Office Version:Excel 2003
Posts: 3
CF250 is becoming part of the community
Compare Columns

Please Register to Remove these Ads

Hi
My first time here so hi to everyone

I have two columns of adjacent data Call them A & B (although this could differ)

If the data in the second colum is not equal to, blank cell or contains the words "CAT", "DOG" or "ELEPHANT" then the content of the cell in the second column should REPLACE the content of the adjacent cell in column A (in this example) leaving B blank, otherwise column B remains unchanged

I wanting to run it from a form to enter the column references using a refedit (because the data as I said is not always in A & B it could be K & L for example) then a command button to run the VBA, .

In other words,

If column B contains anything other than , blank cell "CAT", "DOG" or "ELEPHANT" then the content of the cell in column B should REPLACE the content of the adjacent cell in column A leaving the cell in B blank, otherwise column B remains unchanged.

If using the form or refedit is a problem then a standard macro I could run based on columns A & B would be most gratefull.

Thanks

Any help would be appreciated
Reply With Quote
  #2  
Old 07-04-2009, 09:46 PM
venkat1926 venkat1926 is offline
Registered User
 
Join Date: 17 Jun 2009
Location: Chennai,India
MS Office Version:Excel 2002
Posts: 76
venkat1926 is becoming part of the community
re: Compare Columns

try the macro test
there is an input box which will come up. type the column letter for e.g. B.
the entries cat, dog etc should be exact without any other extra spaces etc.
row 1 has column hadings
the macro is

Code:
Sub test()
Dim rng As Range, c As Range, col As String
col = InputBox("type the column you are considering e.g. B")

Worksheets("sheet1").Activate
Set rng = Range(Range(col & 2), Cells(Rows.Count, col).End(xlUp))
For Each c In rng
'MsgBox c

If c = "" Or c = "cat" Or c = "dog" Or c = "elephant" Then
c.Cut
c.Offset(0, -1).Select
ActiveSheet.Paste
End If
Next c
End Sub
Reply With Quote
  #3  
Old 07-05-2009, 03:24 AM
CF250 CF250 is offline
Registered User
 
Join Date: 04 Jul 2009
Location: London, England
MS Office Version:Excel 2003
Posts: 3
CF250 is becoming part of the community
Re: Compare Columns

Cheers for the reply Venkat1926


sort of there

I have attached a sample worksheet

So it leaves anything that is in column B and is in the or statement in your code alone , but replaces the cell in column A with whatever is in column B

Hope that makes sense

Is there anyway one can
Attached Files
File Type: xls merge 2 columns.xls (26.0 KB, 7 views)
Reply With Quote
  #4  
Old 07-13-2009, 07:20 AM
CF250 CF250 is offline
Registered User
 
Join Date: 04 Jul 2009
Location: London, England
MS Office Version:Excel 2003
Posts: 3
CF250 is becoming part of the community
Unhappy Re: Compare Columns

Hi
venkat1926 solution sort of works but the wrong way round.
ie it replaces content of column A with the content of column B if it matches the references in the OR statement.

I want it to replace the contents of column A if it does NOT match

Can anyone help ?
Reply With Quote


Reply

Bookmarks


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
Trackbacks are Off
Pingbacks are Off
Refbacks are Off

Forum Jump