View Single Post
  #3   Report Post  
Posted to microsoft.public.excel.programming
FSt1 FSt1 is offline
external usenet poster
 
Posts: 3,942
Default How do I assign variables

hi
what are we trying to do with this line....
paycode1 = Cells(j, 12).Formula = Cells(j, 7) * Cells(j, 11)

it seems you are trying to put value in paycode1 AND put a formula for that
value in cells(j, 12). cant do that
are you trying to put a formula in the cell above or just a value?
paycode1 = cells(j, 7).value * Cells(j, 11).value
cells(j, 12).value = paycode1.value
or for formula
cells(j, 12).FormulaR1C1 = "=RC[-5]+RC[-1]"

post back with more detail as to what you are trying to do with this line
because it has syntax error all over it.

Regards
FSt1



"KevinM" wrote:

Hi. I'm new to VBA and wrote this code to calculate pay. It's working but
what I also need is to have calculations done by taking the data and adding
them and then dividing them. I wanted to assign varibles to the IF
statements to allow me make the addition and division easier but its not
working. How do I assign variables to allow me to add and divide? Here is
the code. Thank you in advance.

Sub calculate_retropay()

Dim paycode12 As Integer
Dim paycode13 As Integer
Dim paycode1E As Integer
Dim paycode1H As Integer
Dim paycode1I As Integer
Dim paycode1J As Integer
Dim paycode1 As Integer

'this will search for the pay period in column C
Enterpp = InputBox("Please enter the period number ie 2008-21-0")
finalrow = Cells(65536, 3).End(xlUp).Row
finalrow1 = Cells(65536, 6).End(xlUp).Row

For i = 1 To finalrow
For j = 1 To finalrow1


'takes the value of what pay period is keyed in
If Cells(i, 3).Value = Enterpp Then
'if paycode =1 then take the new rate * by hours
If Cells(j, 6).Value = 1 Then
paycode1=Cells(j, 12).Formula = Cells(j, 7) * Cells(j, 11)
***when I assign this as a variable it doesn't work
Else
If Cells(j, 6).Value = 5 Then
Cells(j, 12).Value = "test" ** if its set like this
when it works fine
Else
if paycode =12 then take the new rate * by hours
If Cells(j, 6).Value = 12 Then
Cells(j, 12).Formula = Cells(j, 7) * Cells(j, 11)