Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Microsoft Office > Excel VBA > Excel VBA
|
Excel VBA Discuss using VBA for Excel programming.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Excel VBA section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old January 31st, 2007, 02:38 PM
Registered User
 
Join Date: Jan 2007
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default Need a little help on college project

Hi everyone i am new here and this is my first post. Any ways the problem i am facing is executing the next code after an IF Then statment. What i am trying to do is copy data from one work sheet into another work sheet with validation.

Sub Reserve_button_Click()

If Available.Text = "No" Then MsgBox "Sorry the vehicle you selected is not available", vbExclamation

If Available.Text = "yes" Then
Title = ComboBox_Title
FirstName = Worksheets("Enquiries").Range("D21").Value
LastName = Worksheets("Enquiries").Range("D23").Value
Address1 = Worksheets("Enquiries").Range("H20").Value
Address2 = Worksheets("Enquiries").Range("H22").Value
City = Worksheets("Enquiries").Range("H24").Value
PostCode = Worksheets("Enquiries").Range("H26").Value
StartDate = Worksheets("Enquiries").Range("D12").Value
EndDate = Worksheets("Enquiries").Range("D14").Value

If FirstName = "" Then MsgBox "Please put in a First name", vbInformation
If LastName = "" Then MsgBox "Please put in a Last Name", vbInformation
If Address1 = "" Then MsgBox " Please put in vaild adree e.g. 17 walk down street", vbInformation
If City = "" Then MsgBox "Please enter a vaild city", vbInformation
If PostCode = "" Then MsgBox "Please enter a vaild postcode e.g. P7 7AB", vbInformation
If StartDate = "" Then MsgBox "Please enter the date you wish to rent the vehicle e.g. 12/02/2007", vbInformation
If EndDate = "" Then MsgBox "Please enter the date you wish to return the vehicle e.g. 12/02/2007", vbInformation

Else

After Else the code on the bottom should excute but for some reason its not working.

Row = 2
Do
Row = Row + 1

Reservation = Worksheets("Reservation").Range("A" & Row).Value

Loop Until IsEmpty(Reservation)

Worksheets("Reservation").Range("B" & Row).Value = FirstName
Worksheets("Reservation").Range("C" & Row).Value = LastName
Worksheets("Reservation").Range("D" & Row).Value = Address1
Worksheets("Reservation").Range("E" & Row).Value = Address2
Worksheets("Reservation").Range("F" & Row).Value = City
Worksheets("Reservation").Range("G" & Row).Value = PostCode
Worksheets("Reservation").Range("A" & Row).Value = Title
Worksheets("Reservation").Range("H" & Row).Value = StartDate
Worksheets("Reservation").Range("I" & Row).Value = EndDate

End If
End Sub


If any one can help that would be great

 
Old January 31st, 2007, 05:44 PM
Registered User
 
Join Date: Jan 2007
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Default

limpep,

Instead of:-

Row = 2
Do
Row = Row + 1
Reservation = Worksheets("Reservation").Range("A" & Row).Value
Loop Until IsEmpty(Reservation)

Try:-

rw = 2
Do
rw = rw + 1
Loop Until IsEmpty(Worksheets("reservation").Cells(rw, 1))
'change row to rw in any code underneath


 
Old January 31st, 2007, 06:39 PM
Registered User
 
Join Date: Jan 2007
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Nop that didnt work. Any more ideas?

 
Old January 31st, 2007, 07:02 PM
Registered User
 
Join Date: Jan 2007
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Is your problem an error message occurs or that nothing appears in cols B to I ?
regards


 
Old January 31st, 2007, 07:11 PM
Registered User
 
Join Date: Jan 2007
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default

No bec before i add the validation everything was working fine when i start to add the if then and else statments alli got was the only the top code working the bottom half didnt work.

 
Old February 1st, 2007, 06:47 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 173
Thanks: 0
Thanked 3 Times in 3 Posts
Default

I think that you don't need the else statement where you've put it. This is because the code in this pursuant section will only fire off when Available.Text does not equal "yes" whereas the operations the code are performing seem to me to follow on from the sense checking above. I've reworked your code to what I think you meant to be running.

HTH,
Maccas

Code:
Sub Reserve_button_Click()

    If Available.Text = "No" Then

        MsgBox "Sorry the vehicle you selected is not available", vbExclamation

    ElseIf Available.Text = "Yes" Then

        ' ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        ' Extract the details
        ' ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

        Title = ComboBox_Title
        FirstName = Worksheets("Enquiries").Range("D21").Value
        LastName = Worksheets("Enquiries").Range("D23").Value
        Address1 = Worksheets("Enquiries").Range("H20").Value
        Address2 = Worksheets("Enquiries").Range("H22").Value
        City = Worksheets("Enquiries").Range("H24").Value
        PostCode = Worksheets("Enquiries").Range("H26").Value
        StartDate = Worksheets("Enquiries").Range("D12").Value
        EndDate = Worksheets("Enquiries").Range("D14").Value

        ' ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        ' Sense check the details
        ' ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

        If FirstName = "" Then
            MsgBox "Please put in a First name", vbInformation
            Exit Sub
        End If

        If LastName = "" Then
            MsgBox "Please put in a Last Name", vbInformation
            Exit Sub
        End If

        If Address1 = "" Then
            MsgBox " Please put in vaild address e.g. 17 Walk Down Street", vbInformation
            Exit Sub
        End If

        If City = "" Then
            MsgBox "Please enter a vaild city", vbInformation
            Exit Sub
        End If

        If PostCode = "" Then
            MsgBox "Please enter a vaild postcode e.g. P7 7AB", vbInformation
            Exit Sub
        End If

        If StartDate = "" Then
            MsgBox "Please enter the date you wish to rent the vehicle e.g. 12/02/2007", vbInformation
            Exit Sub
        End If

        If EndDate = "" Then
            MsgBox "Please enter the date you wish to return the vehicle e.g. 12/02/2007", vbInformation
            Exit Sub
        End If

        ' ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        ' Find the next empty row on the Reservation sheet
        ' ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

        Row = 2
        Do
            Row = Row + 1
            Reservation = Worksheets("Reservation").Range("A" & Row).Value
        Loop Until IsEmpty(Reservation)

        ' ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        ' Output the data to the Reservation sheet
        ' ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

        Worksheets("Reservation").Range("B" & Row).Value = FirstName
        Worksheets("Reservation").Range("C" & Row).Value = LastName
        Worksheets("Reservation").Range("D" & Row).Value = Address1
        Worksheets("Reservation").Range("E" & Row).Value = Address2
        Worksheets("Reservation").Range("F" & Row).Value = City
        Worksheets("Reservation").Range("G" & Row).Value = PostCode
        Worksheets("Reservation").Range("A" & Row).Value = Title
        Worksheets("Reservation").Range("H" & Row).Value = StartDate
        Worksheets("Reservation").Range("I" & Row).Value = EndDate

    Else

        MsgBox "Available.Text not recognised", vbExclamation

    End If

End Sub

 
Old February 1st, 2007, 09:26 AM
Registered User
 
Join Date: Jan 2007
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default

They guys thanks for all your help but i have fixed the problem.

Code:
Sub Reserve_button_Click()

If Available.Text = "No" Then MsgBox "Sorry the vehicle you selected is not available", vbExclamation
flg = False
If Available.Text = "yes" Then
    Title = ComboBox_Title
    With Sheets("Enquiries")
        FirstName = Worksheets("Enquiries").Range("D21").Value
        LastName = Worksheets("Enquiries").Range("D23").Value
        Address1 = Worksheets("Enquiries").Range("H20").Value
        Address2 = Worksheets("Enquiries").Range("H22").Value
        City = Worksheets("Enquiries").Range("H24").Value
        PostCode = Worksheets("Enquiries").Range("H26").Value
        StartDate = Worksheets("Enquiries").Range("D12").Value
        EndDate = Worksheets("Enquiries").Range("D14").Value
    End With

    If FirstName = "" Then MsgBox "Please put in a First name", vbInformation: flg = True
    If LastName = "" Then MsgBox "Please put in a Last Name", vbInformation: flg = True
    If Address1 = "" Then MsgBox " Please put in vaild adree e.g. 17 walk down street", vbInformation: flg = True
    If City = "" Then MsgBox "Please enter a vaild city", vbInformation
    If PostCode = "" Then MsgBox "Please enter a vaild postcode e.g. P7 7AB", vbInformation: flg = True
    If StartDate = "" Then MsgBox "Please enter the date you wish to rent the vehicle e.g. 12/02/2007", vbInformation: flg = True
    If EndDate = "" Then MsgBox "Please enter the date you wish to return the vehicle e.g. 12/02/2007", vbInformation: flg = True
    If flg Then Exit Sub

    MyRow = 2
    With Sheets("Reservation")
        Do
            MyRow = MyRow + 1

            Reservation = Empty

        Loop Until IsEmpty(Reservation)

        Worksheets("Reservation").Range("B" & MyRow).Value = FirstName
        Worksheets("Reservation").Range("C" & MyRow).Value = LastName
        Worksheets("Reservation").Range("D" & MyRow).Value = Address1
        Worksheets("Reservation").Range("E" & MyRow).Value = Address2
        Worksheets("Reservation").Range("F" & MyRow).Value = City
        Worksheets("Reservation").Range("G" & MyRow).Value = PostCode
        Worksheets("Reservation").Range("A" & MyRow).Value = Title
        Worksheets("Reservation").Range("H" & MyRow).Value = StartDate
        Worksheets("Reservation").Range("I" & MyRow).Value = EndDate
    End With
End If

End Sub





Similar Threads
Thread Thread Starter Forum Replies Last Post
Website project vs Web Application Project... thenoseknows ASP.NET 2.0 Professional 0 January 14th, 2007 09:47 PM
How do i Call one project to another project kau_shuk VS.NET 2002/2003 8 December 5th, 2006 10:02 AM
UserControl of One Project in Other Project gadhiav ASP.NET 1.0 and 1.1 Professional 2 February 18th, 2006 07:51 AM
Add report of one project into another project tejaswibv Crystal Reports 0 July 13th, 2005 04:40 AM
From 1 project to get access to another project hplim18 Pro VB.NET 2002/2003 0 March 30th, 2004 10:33 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.