Solved

Vb help

Posted on 2011-02-20
2
280 Views
Last Modified: 2012-06-21
Please can you help,

The attached code basically offloads the inputs from the userform onto the "Low Volume" Sheet.

I want to amend this line:-

next_empty.Offset(, 9) = txtstarteddate

So that apposed to inputting the value in Column K sheet4, it places the value in sheet1 Column B ("NewSheet")

Preferably it would start from B2, but should it be easier to keep the same line as that on the other sheet, that should also do.

Many thanks for your help!

Private Sub cmdPopulateRow_Click()
    Sheets("Low Volume").Unprotect Sheets("DataSheet").Range("B2").Value
    
    Dim next_empty As Range
    
    '~~> Get next empty row
    If Sheets("Low Volume").Range("B14") <> "" Then
        Set next_empty = Sheets("Low Volume").Range("B13").End(xlDown).Offset(1)
    Else
        Set next_empty = Sheets("Low Volume").Range("B14")
    End If
    
    'fill in details
    next_empty = txtrecieveddate
    next_empty.Offset(, 5) = txtcustomersname
    next_empty.Offset(, 4) = txtCustomerusername
    next_empty.Offset(, 6) = TextBox1
    next_empty.Offset(, 2) = TextBox3.Value
    next_empty.Offset(, 9) = txtstarteddate
    next_empty.Offset(, 21) = txtcompleteddate
    next_empty.Offset(, 3) = ComboBox1
    next_empty.Offset(, 7) = ComboBox2
    next_empty.Offset(, 8) = ComboBox3
    
    Sheets("Low Volume").Protect Sheets("DataSheet").Range("B2").Value
    
    Unload Me
End Sub

Open in new window

gary-test4.xls
0
Comment
Question by:Gazza83
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
2 Comments
 
LVL 30

Expert Comment

by:SiddharthRout
ID: 34939564
Is this what you want?

Private Sub cmdPopulateRow_Click()
    Dim LastRow As Long
    Dim next_empty As Range
     
    LastRow = Sheets("Low Volume").Range("B" & Rows.Count).End(xlUp).Row + 1
    
    Sheets("Low Volume").Unprotect Sheets("DataSheet").Range("B2").Value
    
    '~~> Get next empty row
    If Sheets("Low Volume").Range("B14") <> "" Then
        Set next_empty = Sheets("Low Volume").Range("B13").End(xlDown).Offset(1)
    Else
        Set next_empty = Sheets("Low Volume").Range("B14")
    End If
    
    'fill in details
    next_empty = txtrecieveddate
    next_empty.Offset(, 5) = txtcustomersname
    next_empty.Offset(, 4) = txtCustomerusername
    next_empty.Offset(, 6) = TextBox1
    next_empty.Offset(, 2) = TextBox3.Value
    Sheets("NewSheet").Range("B" & LastRow) = txtstarteddate
    next_empty.Offset(, 21) = txtcompleteddate
    next_empty.Offset(, 3) = ComboBox1
    next_empty.Offset(, 7) = ComboBox2
    next_empty.Offset(, 8) = ComboBox3
    
    Sheets("Low Volume").Protect Sheets("DataSheet").Range("B2").Value
    
    Unload Me
End Sub

Open in new window


Sid
0
 
LVL 30

Accepted Solution

by:
SiddharthRout earned 500 total points
ID: 34939567
A Typo...

Please use this

Private Sub cmdPopulateRow_Click()
    Dim LastRow As Long
    Dim next_empty As Range
     
    LastRow = Sheets("NewSheet").Range("B" & Rows.Count).End(xlUp).Row + 1
    
    Sheets("Low Volume").Unprotect Sheets("DataSheet").Range("B2").Value
    
    '~~> Get next empty row
    If Sheets("Low Volume").Range("B14") <> "" Then
        Set next_empty = Sheets("Low Volume").Range("B13").End(xlDown).Offset(1)
    Else
        Set next_empty = Sheets("Low Volume").Range("B14")
    End If
    
    'fill in details
    next_empty = txtrecieveddate
    next_empty.Offset(, 5) = txtcustomersname
    next_empty.Offset(, 4) = txtCustomerusername
    next_empty.Offset(, 6) = TextBox1
    next_empty.Offset(, 2) = TextBox3.Value
    Sheets("NewSheet").Range("B" & LastRow) = txtstarteddate
    next_empty.Offset(, 21) = txtcompleteddate
    next_empty.Offset(, 3) = ComboBox1
    next_empty.Offset(, 7) = ComboBox2
    next_empty.Offset(, 8) = ComboBox3
    
    Sheets("Low Volume").Protect Sheets("DataSheet").Range("B2").Value
    
    Unload Me
End Sub

Open in new window


Sid
0

Featured Post

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

How to get Spreadsheet Compare 2016 working with the 64 bit version of Office 2016
You need to know the location of the Office templates folder, so that when you create new templates, they are saved to that location, and thus are available for selection when creating new documents.  The steps to find the Templates folder path are …
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

689 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question