vba cell division

Associate
Joined
2 Jul 2004
Posts
1,820
Location
East Midlands
Hi Guys,

Just wondered if I could have some help, I have a script that pulls a value from a database and pastes it into a cell (D1), with the cell value I am trying to divide it by a certain number depending on its value. Heres what I am trying to write in english:

Code:
Dim pieces As Integer

pieces = Sheets("sheet1").Range("D1").Value

If pieces > 999 Then divide by 2
elseif pieces > 1998 then divide by 3
elseif pieces > 2997 then divide by 4
elseif pieces > 3996 then divide by 5
elseif pieces > 4995 then divide by 6
elseif pieces > 5996 then divide by 7
elseif pieces <= do nothing
endif

Then create a new variable with the newly created number. Not really sure how to go about this so any help would be appreciated.

I trying to do this because the field in the database that I am trying to populate with the new number cannot accept a higher number than 999.

Cheers
B
 
Surely this would end up with highly inaccurate data? If D1 was 5997, and on your database it was divided by 7 then displayed as 856, that's going to be incredibly misleading.

Is there a specific reason you can't increase the limit of the field?
 
1) your if statement is wrong all it will ever do is divide by 2, might be better with a select statement.

2) as for what you are asking its simples

Code:
Dim NewVar as integer

NewVar = pieces / 2
 
Back
Top Bottom