Help rewriting VB Code:

Get_Involved

Active Member
Joined
Jan 26, 2007
Messages
383
How do I get this code to work?

Code:
Private Sub Workbook_Open()
 Dim Ans As String
 Ans = MsgBox("Update Invoice Number (???)", vbYesNo + vbInformation)
 If Ans = vbYes Then
 
 With Sheets("Expense Report").Range("H4")
 .Value = .Value + 1
 
 With Sheets("Legend").Range("Q4")
 .Value = .Value + 1
 
 With Sheets("Legend").Range("R4")
 .Value = . Value + MAX('Bid Calculator'!C29:G29)

Range R4 is the one I am trying to get to work.

I have the code in "ThisWorkbook"
 
Last edited:

Excel Facts

Excel Can Read to You
Customize Quick Access Toolbar. From All Commands, add Speak Cells or Speak Cells on Enter to QAT. Select cells. Press Speak Cells.
Try

Code:
 .Value = . Value + [MAX('Bid Calculator'!C29:G29)]
 
Upvote 0
Thanks shg
That is starting to work the way it is writ it brings up a FALSE then when I take the + Value out it brings a TRUE.
But what it does on the "Bid Calculator" it bring a blank C29:G29.
Getting close except for the blank.
 
Upvote 0
Sorry, I don't follow that.
 
Upvote 0
you are missing 2 End Withs and 1 End If in your code, so it shouldn't produce any result !!
Try

Code:
Private Sub Workbook_Open()
 Dim Ans As String
 Ans = MsgBox("Update Invoice Number (???)", vbYesNo + vbInformation)
If Ans = vbYes Then
     With Sheets("Expense Report").Range("H4")
        .Value = .Value + 1
     End With
         With Sheets("Legend").Range("Q4")
            .Value = .Value + 1
         End With
     With Sheets("Legend").Range("R4")
        .Value = .Value + WorksheetFunction.Max(Sheets("Bid Calculator").Range("C29:G29"))
    End With
End If
End Sub
 
Upvote 0
Thanks Michael M

I redone the code it works.
Except when I update the work it doubles number to be placed in R4. Example 8 when I close workbook then open and click yes to update it doubles to 16.
 
Upvote 0
Maybe you should revisit this part....
Code:
With Sheets("Legend").Range("R4")
        .Value = .Value + WorksheetFunction.Max(Sheets("Bid Calculator").Range("C29:G29"))
    End With

without seeing the data, it might need something like

Code:
With Sheets("Legend").Range("R4")
        .Value = WorksheetFunction.Max(Sheets("Bid Calculator").Range("C29:G29"))+1
End With

OR

With Sheets("Legend").Range("R4")
        .Value = .value+1
End With
 
Upvote 0
The Bid Calculator has 5 columns C29:G29 C29 starts with the number in the legend at R4. D29:G29 increases by 1.
I am trying to get G29 to be placed back into R4 of the Legend after updating.
Hope this makes sense.
Thanks
 
Upvote 0
This then ???

Code:
With Sheets("Legend").Range("R4")
        .Value = WorksheetFunction.Max(Sheets("Bid Calculator").Range("C29:G29"))
End With
 
Upvote 0
Michael M
I went back to the original code.
Had it working but it was only was giving me the Lesser rather than the max number.
There has to be a code to do it. I'll find it one day
Thanks for your help
 
Upvote 0

Forum statistics

Threads
1,215,439
Messages
6,124,877
Members
449,191
Latest member
MoonDancer

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