+ Reply to Thread
Results 1 to 2 of 2

No rush code cleanup help

Hybrid View

MikeinOK No rush code cleanup help 07-27-2012, 02:40 PM
arlu1201 Re: No rush code cleanup help 07-27-2012, 02:50 PM
  1. #1
    Registered User
    Join Date
    07-27-2012
    Location
    United States
    MS-Off Ver
    Excel 2010 /13
    Posts
    11

    No rush code cleanup help

    ***Thank you for fixing the code input!!! Now I know***

    I have this working just fine, and it is just a project to see if I can make a front end in excel as most people can run excel and not all have Access loaded. It would be a input form that is more user friendly but would put said content in a worksheet for me to upload to a sql server.

    I currently have a WKS1("Input") which is user interface and input form / area. WKS2("CSV") is where data is stored once submitted so that it can be easily updated to a database when I wish. WKS 3(Data Sheet") I have my saved variables in named ranges for drop downs in the majority of my input cells.

    I include both sets of code, one is a clear value button that I found source code for clearing the data validation selections, and then added the part to clear text values of two other cells (B3,B15). The other is my submit button, which I got done by myself, but I am sure there is some way to greatly reduce the code, or maybe not since I do not use ranges, just non sequential cells. Only way I could have a blank is if they left B3 Name or B15 description blank.

    //Reset Button
    Sub resetButton_Click()
      Dim rVal As Range
      Dim rCell As Range
      Dim rList As Range
      Dim rName As Range
      Dim rDescr As Range
          
      On Error Resume Next
      Set rName = Range("B3")
      Set rDescr = Range("B15")
      Set rVal = Cells.SpecialCells(xlCellTypeAllValidation)
      On Error GoTo 0
      rName = ClearContents
      rDescr = ClearContents
      If Not rVal Is Nothing Then
        For Each rCell In rVal
          rCell.ClearContents
          With rCell.Validation
            If .Type = xlValidateList Then
              If Left(.Formula1, 1) = "=" Then
                Set rList = ActiveWorkbook.Names(Right(.Formula1, Len(.Formula1) - 1)).RefersToRange
                rCell.Value = rList.Cells(1, 1).Value
              Else
                rCell.Value = Left(.Formula1, InStr(1, .Formula1, ",") - 1)
              End If
            End If
          End With
          Next rCell
      End If
    End Sub
    //Submit Button
    //First line is something I was trying but could not get it functional so went with the other which I came up with myself.

    Private Sub submitButton_Click()
       
        'Worksheets("Input").Range("B3").Copy Destination:=Worksheets("CSV").Cells(Rows.Count, "A").End(xlUp).Offset(1, 0).PasteSpecial
         Worksheets("CSV").Range("a6000").End(xlUp).Offset(1, 0).Value = Worksheets("Input").Range("B3").Value
         Worksheets("CSV").Range("b6000").End(xlUp).Offset(1, 0).Value = Worksheets("Input").Range("B5").Value
         Worksheets("CSV").Range("c6000").End(xlUp).Offset(1, 0).Value = Worksheets("Input").Range("B7").Value
         Worksheets("CSV").Range("d6000").End(xlUp).Offset(1, 0).Value = Worksheets("Input").Range("B9").Value
         Worksheets("CSV").Range("e6000").End(xlUp).Offset(1, 0).Value = Worksheets("Input").Range("B11").Value
         Worksheets("CSV").Range("f6000").End(xlUp).Offset(1, 0).Value = Worksheets("Input").Range("B13").Value
         Worksheets("CSV").Range("g6000").End(xlUp).Offset(1, 0).Value = Worksheets("Input").Range("E3").Value
         Worksheets("CSV").Range("h6000").End(xlUp).Offset(1, 0).Value = Worksheets("Input").Range("E5").Value
         Worksheets("CSV").Range("i6000").End(xlUp).Offset(1, 0).Value = Worksheets("Input").Range("E7").Value
         Worksheets("CSV").Range("j6000").End(xlUp).Offset(1, 0).Value = Worksheets("Input").Range("E9").Value
         Worksheets("CSV").Range("k6000").End(xlUp).Offset(1, 0).Value = Worksheets("Input").Range("E11").Value
         Worksheets("CSV").Range("l6000").End(xlUp).Offset(1, 0).Value = Worksheets("Input").Range("B15").Value
        
    
    
    End Sub
    Last edited by MikeinOK; 07-27-2012 at 03:19 PM.

  2. #2
    Forum Contributor arlu1201's Avatar
    Join Date
    09-09-2011
    Location
    Bangalore, India
    MS-Off Ver
    Excel 2003 & 2007
    Posts
    19,166

    Re: No rush code cleanup help

    I have put the code tags in for you. To do so you have to put [code] at the beginning of your code and [/code] at the end.
    If I have helped, Don't forget to add to my reputation (click on the star below the post)
    Don't forget to mark threads as "Solved" (Thread Tools->Mark thread as Solved)
    Use code tags when posting your VBA code: [code] Your code here [/code]

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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