help in VBA Coding

Shweta

Well-known Member
Joined
Jun 5, 2011
Messages
514
Hi All,

I am facing a problem in my coding

coding is:
For i = 2 To Sheet1.Range("a2").End(xlDown).Row
If Sheet1.Range("G" & i).Value <= 2.5 Then
Sheet1.Range("H" & i).Value = 5
ElseIf Sheet1.Range("G" & i).Value > 2.5 And Sheet1.Range("G" & i).Value <= 3# Then
Sheet1.Range("H" & i).Value = 4.5
ElseIf Sheet1.Range("G" & i).Value > 3# And Sheet1.Range("G" & i).Value <= 3.5 Then
Sheet1.Range("H" & i).Value = 4
ElseIf Sheet1.Range("G" & i).Value > 3.5 And Sheet1.Range("G" & i).Value <= 4# Then
Sheet1.Range("H" & i).Value = 3.5
ElseIf Sheet1.Range("G" & i).Value > 4# And Sheet1.Range("G" & i).Value <= 4.25 Then
Sheet1.Range("H" & i).Value = 3
ElseIf Sheet1.Range("G" & i).Value > 4.25 And Sheet1.Range("G" & i).Value <= 4.5 Then
Sheet1.Range("H" & i).Value = 2
ElseIf Sheet1.Range("G" & i).Value > 4.5 Then
Sheet1.Range("H" & i).Value = 1
End If
Next

In this coding when I enter 3.00 or 4.00 it converts it in 3# or 4# and the second thing is I want to write it with % sign like 3.00%, it is not accepting it. Is there any other way to code it.

Please help me out.

Thanks
Shweta
 

Excel Facts

Why are there 1,048,576 rows in Excel?
The Excel team increased the size of the grid in 2007. There are 2^20 rows and 2^14 columns for a total of 17 billion cells.
If those numbers are percentages then try like this

Code:
ElseIf Sheet1.Range("G" & i).Value > 0.03 And Sheet1.Range("G" & i).Value <= 0.035 Then
 
Upvote 0
In this coding when I enter 3.00 or 4.00 it converts it in 3# or 4#
Don't worry about the # sign... that results because you included a decimal point after the number and no other non-zero digits followed it. That # sign mean the 3 is to be considered as being a Double data type. If you leave the decimal point off, then the number is consider to be an Integer or Long. I don't think the distinction as much meaning in VB itself as VB will coerce numerical data types in whatever way is needed. I believe it may have meaning, though, if you work with any of Windows native API functions as I think some of them may be more sensitive to the data type being passed to them.
 
Upvote 0

Forum statistics

Threads
1,224,582
Messages
6,179,670
Members
452,936
Latest member
anamikabhargaw

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top