VBA variable assigned value changes automatically

bsg001

New Member
Joined
Oct 3, 2016
Messages
7
Hello,

I am creating an application that alters reservation database information for a restaurant. The variables are all declared public and used in multiple procedures. I am having an issue while running a certain code that assigns reservations to a table. The program updates a record in the reservation with table information and guest count information. The problem I am having is the variable assigned to the row number increases value after updating the adult count column. So the next column to update, which is the junior count, gets updated on the next row of the database rather than the current/correct row. There is no code in between that would cause the row number to change. I am posting the code below and would appreciate someone's help. The variable in question is "row1".

Code:
Application.ScreenUpdating = False
On Error GoTo Error:
If Range("Tables_eFloorplan").Find(What:="*," & t1 & "(*", LookIn:=xlValues) Is Nothing Then
gc1 = Sheets("Reservations").Cells(row1, Range("Count_PartyActual").Column) - Sheets("Reservations").Cells(row1, Range("Count_PartyAssigned").Column)
ac1 = Sheets("Reservations").Cells(row1, Range("Count_AdultActual").Column) - Sheets("Reservations").Cells(row1, Range("Count_AdultAssigned").Column)
cc1 = Sheets("Reservations").Cells(row1, Range("Count_ChildActual").Column) - Sheets("Reservations").Cells(row1, Range("Count_ChildAssigned").Column)
ic1 = Sheets("Reservations").Cells(row1, Range("Count_InfantActual").Column) - Sheets("Reservations").Cells(row1, Range("Count_InfantAssigned").Column)
If Sheets("Reservations").Cells(row1, Range("Tables_eFloorplan").Column).value = vbNullString Then
Sheets("Reservations").Cells(row1, Range("Tables_eFloorplan").Column) = "," & t1 & "(" & gc1 & "/" & ac1 & "a0j" & cc1 & "c" & ic1 & "i)"
Else
Sheets("Reservations").Cells(row1, Range("Tables_eFloorplan").Column) = Sheets("Reservations").Cells(row1, Range("Tables_eFloorplan").Column) & "," & t1 & "(" & gc1 & "/" & ac1 & "a0j" & cc1 & "c" & ic1 & "i)"
End If
Else
MsgBox "Table already assigned"
End If
Sheets("Reservations").Cells(row1, Range("Count_AdultAssigned").Column) = Sheets("Reservations").Cells(row1, Range("Count_AdultAssigned").Column) + ac1
Sheets("Reservations").Cells(row1, Range("Count_ChildAssigned").Column) = Sheets("Reservations").Cells(row1, Range("Count_ChildAssigned").Column) + cc1
Sheets("Reservations").Cells(row1, Range("Count_InfantAssigned").Column) = Sheets("Reservations").Cells(row1, Range("Count_InfantAssigned").Column) + ic1
Sheets("Reservations").Cells(row1, Range("Status_Reservation").Column).value = "Assigned"
With Application.WorksheetFunction
Sheets("Reservations").Cells(row1, Range("Notes_History").Column).value = "Assigned to table " & t1 & "  by [" & .Index(Range("User_LAN"), .Match(Range("User_Active"), Range("User_PERNER"), 0)) & " : " & Now & "]" & Chr(10) & Chr(10) & Sheets("Reservations").Cells(row1, Range("Notes_History").Column).value
End With
Run "Selection_Clear"
Exit Sub
Error:
subname = "'Tables_Assign'"
Run "Error_Report"
End Sub

The error occurs after completing line
Code:
Sheets("Reservations").Cells(row1, Range("Count_AdultAssigned").Column) = Sheets("Reservations").Cells(row1, Range("Count_AdultAssigned").Column) + ac1

and changes at line

Code:
Sheets("Reservations").Cells(row1, Range("Count_ChildAssigned").Column) = Sheets("Reservations").Cells(row1, Range("Count_ChildAssigned").Column) + cc1

Thanks for your help!
 
What procedure is that code in?
 
Upvote 0

Excel Facts

Spell Check in Excel
Press F7 to start spell check in Excel. Be careful, by default, Excel does not check Capitalized Werds (whoops)
Hey everyone, I figured out the problem. The database contains a field that calculates the guest count for each reservation, and this in turn supplies information to the listbox where users select the name of the reservation to be altered. Every time a change was made to the database, that listbox was re-calculated as well and the selection was re-applied. Long story short, all I had to do was unselect the record in the listbox on the form at the beginning of my code. I want to thank everyone for their help, though. I know without seeing the entire project it was hard to understand what was going on. You all rock, though...it's thanks to users like you that I am even able to complete this project!
 
Upvote 0

Forum statistics

Threads
1,214,904
Messages
6,122,169
Members
449,070
Latest member
webster33

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