Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 7
Default Visual Basic Compile Error

I created an Expense Voucher spreadsheet that automatically calcs
reimbursements due,using the following code:

Function Calc_ME_Charges()

'Initialize variables
x = 12
y = 6
ME_total = 0


'Loop through Travel Expenses
For Each Cells(x, y) In Cells(21, 24)
If Cells(x, y).Value = "ME" Then
ME_total = ME_total + Cells(x + 1, y + 1).Value
y = y + 3

'Check for end of row
If y = 27 Then
x = x + 1
'Reset y to beginning of row
y = 6
End If

End If
Loop


I get a Visual Basic Compile Error: Variable Required - Can't Assign to
this expression, and I am unable to close out of VB. The result on the cells
in the Excel Spreadsheet is #NAME?. Any suggestions or ideas to resolve
would be appreciated.

Thanks!
  #2   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 40
Default Visual Basic Compile Error

I assume you start at y=6, then scan down 1 by 1 ? then if ="ME" get the
offset value (0,+1)?

"k3639" wrote:

I created an Expense Voucher spreadsheet that automatically calcs
reimbursements due,using the following code:

Function Calc_ME_Charges()

'Initialize variables
x = 12
y = 6
ME_total = 0


'Loop through Travel Expenses
For Each Cells(x, y) In Cells(21, 24)
If Cells(x, y).Value = "ME" Then
ME_total = ME_total + Cells(x + 1, y + 1).Value
y = y + 3

'Check for end of row
If y = 27 Then
x = x + 1
'Reset y to beginning of row
y = 6
End If

End If
Loop


I get a Visual Basic Compile Error: Variable Required - Can't Assign to
this expression, and I am unable to close out of VB. The result on the cells
in the Excel Spreadsheet is #NAME?. Any suggestions or ideas to resolve
would be appreciated.

Thanks!

  #3   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 7
Default Visual Basic Compile Error

Yes, when I enable macros in the spreadsheet it immediately jumps to VB and
highlights the Cells Reference with a Compile Error, Variable Required unable
to assign to this expression.

When I try to locate the Cells Reference it says it is Hidden.

"scottfoxall" wrote:

I assume you start at y=6, then scan down 1 by 1 ? then if ="ME" get the
offset value (0,+1)?

"k3639" wrote:

I created an Expense Voucher spreadsheet that automatically calcs
reimbursements due,using the following code:

Function Calc_ME_Charges()

'Initialize variables
x = 12
y = 6
ME_total = 0


'Loop through Travel Expenses
For Each Cells(x, y) In Cells(21, 24)
If Cells(x, y).Value = "ME" Then
ME_total = ME_total + Cells(x + 1, y + 1).Value
y = y + 3

'Check for end of row
If y = 27 Then
x = x + 1
'Reset y to beginning of row
y = 6
End If

End If
Loop


I get a Visual Basic Compile Error: Variable Required - Can't Assign to
this expression, and I am unable to close out of VB. The result on the cells
in the Excel Spreadsheet is #NAME?. Any suggestions or ideas to resolve
would be appreciated.

Thanks!

  #4   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 40
Default Visual Basic Compile Error

Firstly, try declaring the variables by using the Dim statment. See if that
works, that the usual error under variables not delclared error message!

Function Calc_ME_Charges()


Dim x As Long, y As Long, Me_total As Long


'Initialize variables
x = 12
y = 6
ME_total = 0


'Loop through Travel Expenses
For Each Cells(x, y) In Cells(21, 24)
If Cells(x, y).Value = "ME" Then
ME_total = ME_total + Cells(x + 1, y + 1).Value
y = y + 3

'Check for end of row
If y = 27 Then
x = x + 1
'Reset y to beginning of row
y = 6
End If

End If
Loop





"k3639" wrote:

Yes, when I enable macros in the spreadsheet it immediately jumps to VB and
highlights the Cells Reference with a Compile Error, Variable Required unable
to assign to this expression.

When I try to locate the Cells Reference it says it is Hidden.

"scottfoxall" wrote:

I assume you start at y=6, then scan down 1 by 1 ? then if ="ME" get the
offset value (0,+1)?

"k3639" wrote:

I created an Expense Voucher spreadsheet that automatically calcs
reimbursements due,using the following code:

Function Calc_ME_Charges()

'Initialize variables
x = 12
y = 6
ME_total = 0


'Loop through Travel Expenses
For Each Cells(x, y) In Cells(21, 24)
If Cells(x, y).Value = "ME" Then
ME_total = ME_total + Cells(x + 1, y + 1).Value
y = y + 3

'Check for end of row
If y = 27 Then
x = x + 1
'Reset y to beginning of row
y = 6
End If

End If
Loop


I get a Visual Basic Compile Error: Variable Required - Can't Assign to
this expression, and I am unable to close out of VB. The result on the cells
in the Excel Spreadsheet is #NAME?. Any suggestions or ideas to resolve
would be appreciated.

Thanks!

  #5   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 35,218
Default Visual Basic Compile Error

This line doesn't make sense to me:

For Each Cells(x, y) In Cells(21, 24)

Cells(21,24) is one cell--so why try to loop.

But worse, cells(x,y) is a specific cell in the worksheet. It's not a variable
that you can use in the for/next loop.

More normal samples would look like:

dim myCell as range
for each mycell in worksheets("sheet1").range("a1:a99")

But I don't understand what you're really doing.





k3639 wrote:

I created an Expense Voucher spreadsheet that automatically calcs
reimbursements due,using the following code:

Function Calc_ME_Charges()

'Initialize variables
x = 12
y = 6
ME_total = 0


'Loop through Travel Expenses
For Each Cells(x, y) In Cells(21, 24)
If Cells(x, y).Value = "ME" Then
ME_total = ME_total + Cells(x + 1, y + 1).Value
y = y + 3

'Check for end of row
If y = 27 Then
x = x + 1
'Reset y to beginning of row
y = 6
End If

End If
Loop


I get a Visual Basic Compile Error: Variable Required - Can't Assign to
this expression, and I am unable to close out of VB. The result on the cells
in the Excel Spreadsheet is #NAME?. Any suggestions or ideas to resolve
would be appreciated.

Thanks!


--

Dave Peterson


  #6   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 7
Default Visual Basic Compile Error

I will attach a copy of the spreadsheet, just one page, to show you, but the
code was written by one of our accountants, and she has handwritten
instructions on what she is trying to accomplish. basically, she wants to
calculate meal and mileage totals, that is why the loop is included, because
these are two separate modules.





"Dave Peterson" wrote:

This line doesn't make sense to me:

For Each Cells(x, y) In Cells(21, 24)

Cells(21,24) is one cell--so why try to loop.

But worse, cells(x,y) is a specific cell in the worksheet. It's not a variable
that you can use in the for/next loop.

More normal samples would look like:

dim myCell as range
for each mycell in worksheets("sheet1").range("a1:a99")

But I don't understand what you're really doing.





k3639 wrote:

I created an Expense Voucher spreadsheet that automatically calcs
reimbursements due,using the following code:

Function Calc_ME_Charges()

'Initialize variables
x = 12
y = 6
ME_total = 0


'Loop through Travel Expenses
For Each Cells(x, y) In Cells(21, 24)
If Cells(x, y).Value = "ME" Then
ME_total = ME_total + Cells(x + 1, y + 1).Value
y = y + 3

'Check for end of row
If y = 27 Then
x = x + 1
'Reset y to beginning of row
y = 6
End If

End If
Loop


I get a Visual Basic Compile Error: Variable Required - Can't Assign to
this expression, and I am unable to close out of VB. The result on the cells
in the Excel Spreadsheet is #NAME?. Any suggestions or ideas to resolve
would be appreciated.

Thanks!


--

Dave Peterson

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
Compile Error Argument Not optional [email protected] Excel Discussion (Misc queries) 1 August 16th 06 04:58 PM
Compile error in hidden module Chris Reynolds Excel Discussion (Misc queries) 3 March 10th 06 07:11 PM
MS Visual Basic Error...from MAcro G118 Excel Discussion (Misc queries) 0 December 12th 05 05:56 PM
Linking to Visual Basic for Applications Help Files Glynn Excel Discussion (Misc queries) 0 October 8th 05 01:29 AM
changing the visual basic in office 2003 to visual studio net bigdaddy3 Excel Discussion (Misc queries) 1 September 13th 05 10:57 AM


All times are GMT +1. The time now is 01:18 AM.

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

About Us

"It's about Microsoft Excel"