code_junkie

Making Excel macro for fast data entering ::: VBA ::: Excel :::

Nov 13th, 2011
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.52 KB | None | 0 0
  1. Dim LastCol As Integer
  2. Dim CurRow As Integer
  3.  
  4.  
  5. Private Sub UpdateCells()
  6. Dim Col As Variant
  7. Dim ColumnOrder As Range
  8.  
  9. 'Range that specifies data entry order'
  10. Set ColumnOrder = Range("A3:A15")
  11.  
  12. LastCol = LastCol + 1
  13.  
  14. If LastCol > WorksheetFunction.CountA(ColumnOrder) Then
  15. LastCol = 1
  16. CurRow = CurRow + 1
  17. End If
  18.  
  19. Col = Range("A3").Offset(0, LastCol)
  20. Range(Col & CurRow) = TextBox1.Value
  21. TextBox1 = ""
  22.  
  23. End Sub
  24.  
  25. Private Sub TextBox1_KeyDown(ByVal KeyCode As MSForms.ReturnInteger, ByVal Shift As Integer)
  26. If KeyCode = 13 Then
  27. UpdateCells
  28. End If
  29. End Sub
  30.  
  31. Private Sub UserForm_Initialize()
  32. CurRow = ActiveCell.Row
  33. End Sub
  34.  
  35. Function FindLastRow()
  36. 'Assuming that data starts in A1'
  37. r = ActiveSheet.UsedRange.Rows.Count
  38. c = ActiveSheet.UsedRange.Columns.Count
  39. FindLastRow = r
  40. End Function
  41.  
  42. Sub LastRow()
  43. LastRowA = ExecuteExcel4Macro("GET.DOCUMENT(10)")
  44. LastRowB = ActiveSheet.Cells.SpecialCells(xlCellTypeLastCell).Row
  45. End Sub
  46.  
  47. Private Sub Worksheet_Change(ByVal Target As Range)
  48.  
  49. Dim sText As String
  50.  
  51. Application.EnableEvents = True
  52.  
  53. If Target.Column = 1 Then 'Four digits entered in col A
  54. sText = CStr(Target.Value) 'convert to string
  55. If Len(sText) = 4 Then
  56. Target.Offset(0, 4).Value = Left$(sText, 1) 'write to E
  57. Target.Offset(0, 3).Value = Mid$(sText, 2, 1) 'D
  58. Target.Offset(0, 5).Value = Mid$(sText, 3, 1) 'F
  59. Target.Offset(0, 6).Value = Mid$(sText, 4, 1) 'G
  60. End If
  61. End If
  62.  
  63. Application.EnableEvents = True
  64.  
  65. End Sub
  66.  
  67. =VALUE(MID(Inputs,N,1))
Add Comment
Please, Sign In to add comment