Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 51
Default passing a non numeric cell for numeric comparison

Hello, I have a problem with my vba code,, which compares the values of first and second columns. And if value of first column is smaller than the second one, assigns "1" to third column.

However, if one of the cells is not numeric code stops to work and gives error. Unfortunately some of my cells have to be string. In that situation I just want to pass that row. How can I do it? I couldn't manage it. My codes are as below:


For i = 1 To 100
If Sheets("Sheet1").Cells(i, 1) < Sheets("Sheet1").Cells(i, 2) Then
Sheets("Sheet1").Cells(i, 3) = 1
Else
Sheets("Sheet1").Cells(i, 3) = 0
End If
Next


I will be very glad if you help me. Thanks a lot.
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,872
Default passing a non numeric cell for numeric comparison

Hi,

Am Tue, 28 Aug 2012 02:08:19 -0700 (PDT) schrieb oercim:

However, if one of the cells is not numeric code stops to work and gives error. Unfortunately some of my cells have to be string. In that situation I just want to pass that row. How can I do it? I couldn't manage it. My codes are as below:

For i = 1 To 100
If Sheets("Sheet1").Cells(i, 1) < Sheets("Sheet1").Cells(i, 2) Then
Sheets("Sheet1").Cells(i, 3) = 1
Else
Sheets("Sheet1").Cells(i, 3) = 0
End If
Next


try:

For i = 1 To 100
With Sheets("Sheet1")
If IsNumeric(.Cells(i, 1)) And _
IsNumeric(.Cells(i, 2)) Then
.Cells(i, 3) = -(.Cells(i, 1) < .Cells(i, 2))
End If
End With
Next


Regards
Claus Busch
--
Win XP PRof SP2 / Vista Ultimate SP2
Office 2003 SP2 /2007 Ultimate SP2
  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 51
Default passing a non numeric cell for numeric comparison

28 Ağustos 2012 Salı 12:24:19 UTC+3 tarihinde Claus Busch yazdı:
Hi,



Am Tue, 28 Aug 2012 02:08:19 -0700 (PDT) schrieb oercim:



However, if one of the cells is not numeric code stops to work and gives error. Unfortunately some of my cells have to be string. In that situation I just want to pass that row. How can I do it? I couldn't manage it. My codes are as below:




For i = 1 To 100


If Sheets("Sheet1").Cells(i, 1) < Sheets("Sheet1").Cells(i, 2) Then


Sheets("Sheet1").Cells(i, 3) = 1


Else


Sheets("Sheet1").Cells(i, 3) = 0


End If


Next




try:



For i = 1 To 100

With Sheets("Sheet1")

If IsNumeric(.Cells(i, 1)) And _

IsNumeric(.Cells(i, 2)) Then

.Cells(i, 3) = -(.Cells(i, 1) < .Cells(i, 2))

End If

End With

Next





Regards

Claus Busch

--

Win XP PRof SP2 / Vista Ultimate SP2

Office 2003 SP2 /2007 Ultimate SP2


Thank you very much Claus Busch. This was very helpful for me.
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to delete numeric characters in a cell with alpha numeric char Zak Excel Programming 1 May 5th 10 04:06 PM
TO DELETE ONLY NUMERIC VALUES IN A CHARACTER AND NUMERIC CELL IN ramesh k. goyal - abohar[_2_] Excel Discussion (Misc queries) 1 October 28th 09 06:50 AM
How do I copy numeric section of cell from alpha-numeric cell ACCAguy Excel Worksheet Functions 8 September 8th 08 12:46 PM
only extract numeric value from alpha numeric cell Fam via OfficeKB.com Excel Discussion (Misc queries) 5 April 26th 06 06:49 PM
Match Single Numeric Criteria and Return Multiple Numeric Labels Sam via OfficeKB.com Excel Worksheet Functions 0 December 29th 05 08:44 PM


All times are GMT +1. The time now is 09:22 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"