Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 05-20-2013, 08:17 AM
tomlam tomlam is offline how to divide into group Windows 7 64bit how to divide into group Office 2007
Advanced Beginner
how to divide into group
 
Join Date: Oct 2012
Posts: 33
tomlam is on a distinguished road
Default how to divide into group

Dear Sir/Madam

if apple, orange ,banana in column a
then column c will show as file



apple=1
orange=2
banana=3

but the follow programme don't work, how to do
Code:
Sub group()
For i = 1 To 6
  If Range("a" & i).Value = apple Then
    Range("C" & i).Value = 1
  End If
Next i
For i = 1 To 6
  If Range("a" & i).Value = orange Then
    Range("C" & i).Value = 2
  End If
Next i
For i = 1 To 6
  If Range("a" & i).Value = banana Then
    Range("C" & i).Value = 3
  End If
Next i
End Sub
Thanks
Tom
Attached Files
File Type: xls apple.xls (26.0 KB, 11 views)

Last edited by macropod; 05-20-2013 at 04:38 PM. Reason: Added code tags & formatting
Reply With Quote
  #2  
Old 05-20-2013, 04:43 PM
macropod's Avatar
macropod macropod is online now how to divide into group Windows 7 32bit how to divide into group Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,956
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

The basic problem with your code is that you haven't enclosed your string variables in quotes. You also haven't dimensioned your 'i' variable and your code could be made more efficient. Try:
Code:
Sub group()
Dim i As Long
For i = 1 To 6
  Select Case Range("a" & i).Value
    Case "apple": Range("C" & i).Value = 1
    Case "orange": Range("C" & i).Value = 2
    Case "banana": Range("C" & i).Value = 3
  End Select
Next i
End Sub
PS: When posting code, please use the code tags. They're on the 'Go Advanced' tab.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #3  
Old 05-20-2013, 09:46 PM
tomlam tomlam is offline how to divide into group Windows 7 64bit how to divide into group Office 2007
Advanced Beginner
how to divide into group
 
Join Date: Oct 2012
Posts: 33
tomlam is on a distinguished road
Default

Thank Paul . The progamme work ...thank you
Reply With Quote
Reply

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
how to divide into group How to total 12 columns and divide them to get a percentage Triscia Word Tables 1 01-15-2013 07:39 AM
how to divide into group formula divide by serio error vthomeschoolmom Excel 1 04-18-2012 02:29 PM
divide page into 4 parts aclark17 Word 4 01-17-2012 09:04 AM
Divide by zero error doublejoy Excel 1 08-22-2009 03:10 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 07:03 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2024 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft