|
-
May 23rd, 2012, 01:47 PM
#1
Thread Starter
Lively Member
[RESOLVED] Form data excel sheet - yeah i know whats new!
Hi all,
I've got a excel workbook that i need to be able to automate standard info into via a form, most of the code ive seen online so far is nice a easy, but they all have a similar theme, for the data to import at the bottom of the sheet, where as i would prefer the information to populate at the top.
should be easy enough... but i'm hitting a brick wall. heres what i have so far.
the only code that works is the insert row and user form initialise, the rest doesnt work at all.
Code:
Private Sub UserForm_Initialize()
Dim Cbranch As Range
Dim cbar As Range
Dim br As Worksheet
Set br = Worksheets("Branch list")
For Each Cbranch In br.Range("BARList")
With Me.cmbBranch
.AddItem Cbranch
.List(.ListCount - 1, 1) = Cbranch.Offset(0, 1).Value
End With
Next Cbranch
For Each cbar In br.Range("BRstatus")
With Me.CmbStatus
.AddItem cbar.Value
End With
Next cbar
End Sub
Private Sub cmdOk_Click()
Dim Cname As Long
Dim Cstatus As Long
Dim Cday As Long
Dim Cbranch As Long
Dim Cchange As Long
Rows("3:3").Select
Selection.Insert Shift:=xlDown, CopyOrigin:=xlFormatFromLeftOrAbove
Range("A2").Select
Range("A3").Select
Cname = txtname.Value.Cells("A3", 0)
Cstatus = CmbStatus.Value.Cells("B3", 0)
Cday = txtday.Value.Cells("C3", 0)
Cbranch = cmbBranch.Value.Cells("E3", 0)
Cchange = txtchange.Value.Cells("F3", 0)
Unload Me
End Sub
-
May 23rd, 2012, 04:01 PM
#2
Re: Form data excel sheet - yeah i know whats new!
try like
vb Code:
Set cel = Range("a3") cel.EntireRow.Insert cel.Offset(-1) = txtname cel.Offset(-1, 1) = cmbstatus.Text cel.Offset(-1, 2) = txtday 'etc
i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next
dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part
come back and mark your original post as resolved if your problem is fixed
pete
-
May 23rd, 2012, 05:42 PM
#3
Thread Starter
Lively Member
Re: Form data excel sheet - yeah i know whats new!
Awesome works like a charm! thanks again!
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|