+ Reply to Thread
Results 1 to 7 of 7

VBA/Macros to Control Active Cell

Hybrid View

  1. #1
    Registered User
    Join Date
    05-29-2016
    Location
    Las Vegas, USA
    MS-Off Ver
    2013
    Posts
    15

    VBA/Macros to Control Active Cell

    Hello To Everyone Taking A Look At This,

    First off, I must say I am very thankful for this forum and John Topley for the Wile E. Coyote, Super Genius help he was able to provide. I hope I can find another Super Genius to help me with VBA/Macros code. And I must let you know I know nothing about it. I have successfully screwed up 4 attempts of creating code, once while watching a YouTube video. Doom on me!

    Overview, a user enters data into the RO-CT and Daily Database sheets (I have populated June 1-4 to provide a working sample). Then on the Daily Report sheet the user performs one action, enters a date in cell B2 and the entire Daily Report becomes populated by date, pulling and calculating the information from both database sheets.

    The issue at hand is the way in which the active cell moves down the page when hitting the enter key and the obnoxious scroll to get to the 1500th row to enter the next bit of data as this database grows.

    On the RO-CT Database Sheet:
    1 Upon opening the active cell will always be A2
    2 Upon hitting the Enter key the active cell will move to column B, then C, then D, and so on until Q (Tax) when the entry is considered completed (Ignore column R (Total) , it is just a SUM column for error checking).
    3 When cell in Column Q (Tax) is active hitting the Enter key will 1. Push data entered in row 2 down to row 3, and 2. Reset the active cell back to A2, ready to enter the date from the next invoice.
    Lastly, can RO/CT Number Column be coded to always capitalize (defiantly) even if it needed to be moved in the future (icing on the cake)?

    On the Daily Database Sheet:
    1 Upon opening the active cell will always be A2
    When working in the Customer Collection Section
    2 Upon hitting the Enter key the active cell will move to column B, then C.
    3 When cell in Column C (Amount) is active hitting the Enter key will 1. Push data entered in row 2 down to row 3, and 2. Reset the active cell back to A2, ready to enter more data.
    When working in the Cash Paid Out Section
    4 When cell E2 becomes active hitting the enter key the active cell will move to column F, then G.
    5 When cell in Column G (Amount) is active hitting the Enter key will 1. Push data entered in row 2 down to row 3, and 2. Reset the active cell back to E2, ready to enter more data.
    When working in the Final Section
    6 When cell I2 becomes active hitting the enter key the active cell will move to column J, then K, and so on to column N.
    7 When cell in Column N (Bank Deposit) is active hitting the Enter key will 1. Push data entered in row 2 down to row 3, and 2. Reset the active cell back to I2, ready to enter more data.

    The overall idea is to have each section act or feel as if it is its own little mini database even though it is contained on a single sheet.

    I know for the most part most of this is a repeat of the same code with different cell references and for someone in the know this is probably a joke; however, I appreciate you for taking a look at it.

    Thank you.
    Attached Files Attached Files

  2. #2
    Forum Guru MarvinP's Avatar
    Join Date
    07-23-2010
    Location
    Woodinville, WA
    MS-Off Ver
    Office 365
    Posts
    16,321

    Re: VBA/Macros to Control Active Cell

    Hi,

    This looks like you really need a DataForms tool. There is an old one built into Excel that you can simply add to your quick access toolbar.
    http://spreadsheets.about.com/od/dat..._data_form.htm

    There is also a newer and better (free Data Form) tool from J-Walk. Download it and give it a try.
    http://spreadsheetpage.com/index.php/dataform/home/

    What I think you want has already been built. Simply install and use what is available.
    One test is worth a thousand opinions.
    Click the * Add Reputation below to say thanks.

  3. #3
    Registered User
    Join Date
    05-29-2016
    Location
    Las Vegas, USA
    MS-Off Ver
    2013
    Posts
    15

    Re: VBA/Macros to Control Active Cell

    Hi MarvinP,

    First off, Go Hawks! Throw back, favorite AFC West Team! (No one can hold it against it me since my team is the Jets)

    Down to business.

    I appreciate your insight, just not looking for a form. Already loaded it up and it was big and long, whereas as columns of Excel of nicely on my screen and as you can see most of the work is 10key. I have seen the code for what I want to accomplish on the internet, but when I attempt to copy and paste to create a macros, I Chernobyl my workbook. As I stated, I know what I would like my end result to be, but have no clue as to how get there other than to ask for help.

  4. #4
    Forum Expert
    Join Date
    05-05-2015
    Location
    UK
    MS-Off Ver
    Microsoft Excel for Microsoft 365 MSO (Version 2402 Build 16.0.17328.20068) 64-bit
    Posts
    30,807

    Re: VBA/Macros to Control Active Cell

    See the attached, sheet "Dashboard".

    you can added records for both databases": enter data then "SUBMIT".

    "NEW" clears previous entries.

    Added a few eits on Dates and RO/CT number

    Private Sub CommandButton1_Click()
    
    For I = 1 To 17
    Me.Controls("TextBox" & I) = ""
    Next
    
    
    End Sub
    
    Private Sub CommandButton2_Click()
    
    If Not (IsDate(Me.Controls("TextBox1"))) Or Not (IsDate(Me.Controls("TextBox2"))) Then
        MsgBox "Input error in Date fields" & vbCrLf & VdCrLf & "Entry aborted"
        Exit Sub
    End If
    
    FindString = UCase(Me.Controls("TextBox3"))
    
    If Trim(FindString) <> "" Then
            With Sheets("RO-CT Database").Range("C:C")
                Set Rng = .Find(What:=FindString, _
                                After:=.Cells(.Cells.Count), _
                                LookIn:=xlValues, _
                                LookAt:=xlWhole, _
                                SearchOrder:=xlByRows, _
                                SearchDirection:=xlNext, _
                                MatchCase:=False)
                If Not Rng Is Nothing Then
                    MsgBox "Duplicate RO/CT number: " & FindString & vbCrLf & vbCrLf & "Update aborted"
                    Exit Sub
                Else
                    If Left(FindString, 2) <> "RT" Or Left(FindString, 2) <> "CO" Then
                        MsgBox "Invalid RO/CT number: " & FindString & vbCrLf & vbCrLf & "Update aborted"
                        Exit Sub
                    End If
                End If
            End With
        End If
    
    
    Call RO_CT_Add_Record
    
    For I = 1 To 17
    Cells(2, I) = Me.Controls("TextBox" & I)
    If I = 3 Then Cells(2, 3) = UCase(Me.Controls("TextBox" & I))
    If I >= 4 Then Cells(2, I) = Val(Cells(2, I))
    Next
    
    
    
    End Sub
    
    
    
    Private Sub CommandButton4_Click()
    
    If Not (IsDate(Me.Controls("TextBox33"))) Or Not (IsDate(Me.Controls("TextBox36"))) _
        Or Not (IsDate(Me.Controls("TextBox39"))) Then
        MsgBox "Input error in Date fields" & vbCrLf & VdCrLf & "Entry aborted"
        Exit Sub
    End If
    
    Call Daily_Add_Record
    
    For I = 1 To 3
    If I = 3 Then Cells(2, I) = Val(Me.Controls("TextBox" & 32 + I))
    Cells(2, I) = Me.Controls("TextBox" & 32 + I)
    If I = 3 Then Cells(2, I) = Val(Cells(2, I))
    Next
    
    For I = 1 To 3
    
    Cells(2, I + 4) = Me.Controls("TextBox" & 35 + I)
    If I = 3 Then Cells(2, I + 4) = Val(Cells(2, I + 4))
    Next I
    
    For I = 1 To 6
    Cells(2, I + 8) = Me.Controls("TextBox" & 38 + I)
    If I >= 2 Then Cells(2, I + 8) = Val(Cells(2, I + 8))
    Next
    
    End Sub
    
    
    Private Sub UserForm_Initialize()
    Me.MultiPage1.Value = 0
    End Sub
    Attached Files Attached Files
    Last edited by JohnTopley; 06-26-2016 at 01:30 PM.

  5. #5
    Forum Expert
    Join Date
    05-05-2015
    Location
    UK
    MS-Off Ver
    Microsoft Excel for Microsoft 365 MSO (Version 2402 Build 16.0.17328.20068) 64-bit
    Posts
    30,807

    Re: VBA/Macros to Control Active Cell

    Updated version: now adds records to the end.

    Private Sub CommandButton2_Click()
    
    Worksheets("RO-CT Database").Activate
    
    lr = Cells(Rows.Count, "A").End(xlUp).Row + 1
    
    For i = 1 To 17
    Cells(lr, i) = Me.Controls("TextBox" & i)
    If i = 3 Then Cells(lr, 3) = UCase(Me.Controls("TextBox" & i))
    If i >= 4 Then Cells(lr, i) = Val(Cells(lr, i))
    Next
    
    End Sub
    
    
    
    Private Sub CommandButton4_Click()
    
    Worksheets("Daily Database").Activate
    
    lr = Cells(Rows.Count, "A").End(xlUp).Row + 1
    
    For i = 1 To 3
    Cells(lr, i) = Me.Controls("TextBox" & 32 + i)
    If i = 1 Then Cells(lr, i) = DateValue(Cells(lr, i))
    If i = 3 Then Cells(lr, i) = Val(Cells(lr, i))
    Next
    
    For i = 1 To 3
    
    Cells(lr, i + 4) = Me.Controls("TextBox" & 35 + i)
    If i = 1 Then Cells(lr, i + 4) = DateValue(Cells(lr, i + 4))
    If i = 3 Then Cells(lr, i + 4) = Val(Cells(lr, i + 4))
    Next i
    
    For i = 1 To 6
    Cells(lr, i + 8) = Me.Controls("TextBox" & 38 + i)
    If i = 1 Then Cells(lr, i + 8) = DateValue(Cells(lr, i + 4))
    If i >= 2 Then Cells(lr, i + 8) = Val(Cells(lr, i + 8))
    Next
    
    End Sub
    Attached Files Attached Files

  6. #6
    Forum Expert
    Join Date
    05-05-2015
    Location
    UK
    MS-Off Ver
    Microsoft Excel for Microsoft 365 MSO (Version 2402 Build 16.0.17328.20068) 64-bit
    Posts
    30,807

    Re: VBA/Macros to Control Active Cell

    See attached.
    Attached Files Attached Files

  7. #7
    Forum Expert
    Join Date
    05-05-2015
    Location
    UK
    MS-Off Ver
    Microsoft Excel for Microsoft 365 MSO (Version 2402 Build 16.0.17328.20068) 64-bit
    Posts
    30,807

    Re: VBA/Macros to Control Active Cell

    Further edits added:

    rivate Sub CommandButton2_Click()
    
    Dim Chksum1 As Double
    Dim Chksum2 As Double
    '
    '  Check if validate dates
    '
    
    If Not (IsDate(Me.Controls("TextBox1"))) Or Not (IsDate(Me.Controls("TextBox2"))) Then
        Msg = MsgBox("Input error in Date fields" & vbCrLf & vbCrLf & "Please correct", vbExclamation, "Date errors")
        Exit Sub
    End If
    
    FindString = UCase(Me.Controls("TextBox3"))
    '
    ' Check for duplicate RO/CT number
    '
    If Trim(FindString) <> "" Then
            With Sheets("RO-CT Database").Range("C:C")
                Set Rng = .Find(What:=FindString, _
                                After:=.Cells(.Cells.Count), _
                                LookIn:=xlValues, _
                                LookAt:=xlWhole, _
                                SearchOrder:=xlByRows, _
                                SearchDirection:=xlNext, _
                                MatchCase:=False)
                If Not Rng Is Nothing Then
                      Msg = MsgBox("Duplicate RO/CT number: " & FindString & vbCrLf & vbCrLf & "Do you want to continue ?" _
                    , vbYesNo + vbExclamation, "RO/CT  number")
    
                    If Msg = vbNo Then
                      MsgBox "Please correct the data"
                      Exit Sub
                    Else
                     GoTo nextchk
                    End If
    '
    '  Check if RO/CT number valid format
    '
                Else
                    If Left(FindString, 2) <> "RO" And Left(FindString, 2) <> "CT" Then
                        MsgBox "Invalid RO/CT number: " & FindString & vbCrLf & vbCrLf & "Please correct data"
                        Exit Sub
                    End If
                End If
            End With
        End If
    
    nextchk:
    '
    '  Check Financial balance
    '
    
    Chksum1 = 0
    For i = 4 To 7
    Chksum1 = Chksum1 + Val(Me.Controls("textbox" & i))
    Next i
    Chksum2 = 0
    For i = 8 To 17
    Chksum2 = Chksum2 + Val(Me.Controls("textbox" & i))
    Next i
    If Chksum1 - Chksum2 <> 0 Then
    
       Msg = MsgBox("Finance checksum does not balance: " & vbCrLf & vbCrLf & "Do you want to continue ?" _
                    , vbYesNo + vbExclamation, "Finance Checksum")
    
                If Msg = vbNo Then
                  MsgBox "Please correct the data"
                  Exit Sub
                End If
    
    
    End If
    
    Worksheets("RO-CT Database").Activate
    
    lr = Cells(Rows.Count, "A").End(xlUp).Row + 1
    
    For i = 1 To 17
    Cells(lr, i) = Me.Controls("TextBox" & i)
    If i <= 2 Then Cells(lr, i) = Format(DateValue(Cells(lr, i)), "mm/dd/yy")
    If i = 3 Then Cells(lr, 3) = UCase(Me.Controls("TextBox" & i))
    If i >= 4 Then Cells(lr, i) = Val(Cells(lr, i))
    Next
    
    
    
    End Sub
    Attached Files Attached Files

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Replies: 1
    Last Post: 03-03-2014, 09:06 PM
  2. Active X Check Box that will perform certain macros based upon cell values
    By houseflipsheet in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 01-06-2014, 12:31 AM
  3. [SOLVED] VBA Code to have a repeating form control /Active X control (List box) in every row
    By Ehezve in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 08-28-2013, 08:55 PM
  4. active cell control using scripts
    By Robin01 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 07-18-2006, 07:45 PM
  5. [SOLVED] In macros, an instruction that will return the position of the Active Cell
    By aca in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 01-20-2006, 07:00 PM
  6. Replies: 2
    Last Post: 01-20-2006, 11:00 AM
  7. [SOLVED] Adding a control button to insert a date in the active cell.
    By Mike in forum Excel General
    Replies: 2
    Last Post: 02-15-2005, 03:06 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1