Hi
still a newbe here, and still new to VBA
I have a userform that adds product lines to a sheet "saleslines", which works just fine
Now I am trying to get this data (if any) copied to another sheet in specific cells - but this is where I get into trouble.
any help appreciated!
still a newbe here, and still new to VBA
I have a userform that adds product lines to a sheet "saleslines", which works just fine
VBA Code:
Private Sub CommandButton3_Click()
If TextBox1.Text = "" Then
MsgBox ("Nothing To Add!")
Else
TextBox6 = Format(TextBox6, "#,##0.00")
TextBox8 = Format(TextBox8, "#,##0.00")
TextBox9 = Format(TextBox9, "#,##0.00")
Worksheets("saleslines").Unprotect Password:=""
lastrow = Worksheets("saleslines").Cells(Rows.Count, 1).End(xlUp).row
If Worksheets("saleslines").Cells(lastrow, 1).Value = "ID" Then
TextBox0.Text = 1
Else
TextBox0.Text = Worksheets("saleslines").Cells(lastrow, 1).Value + 1
End If
Worksheets("saleslines").Cells(lastrow + 1, 1).Value = TextBox0.Text
Worksheets("saleslines").Cells(lastrow + 1, 2).Value = TextBox1.Text
Worksheets("saleslines").Cells(lastrow + 1, 3).Value = TextBox2.Text
Worksheets("saleslines").Cells(lastrow + 1, 4).Value = TextBox3.Text
Worksheets("saleslines").Cells(lastrow + 1, 5).Value = TextBox4.Text
Worksheets("saleslines").Cells(lastrow + 1, 6).Value = TextBox5.Text
Worksheets("saleslines").Cells(lastrow + 1, 7).Value = TextBox6.Text
Worksheets("saleslines").Cells(lastrow + 1, 8).Value = TextBox7.Text
Worksheets("saleslines").Cells(lastrow + 1, 9).Value = TextBox8.Text
Worksheets("saleslines").Cells(lastrow + 1, 10).Value = TextBox9.Text
Worksheets("saleslines").Protect Password:=""
End If
End Sub
Now I am trying to get this data (if any) copied to another sheet in specific cells - but this is where I get into trouble.
VBA Code:
Sub CopySaleslinesToSO()
Dim wssl As Worksheet, wsso As Worksheet
Set wssl = Worksheets("saleslines")
Set wsso = Worksheets("SO")
Dim item As Integer
Dim name As String
Dim desc As String
Dim hs As String
Dim pack As String
Dim qty As Double
Dim unit As String
Dim unpr As Double
Dim pric As Double
Dim lastrow As Long
wsso.Activate
wsso.Unprotect Password:=""
Range("a52", Range("v199")).Select
Selection.ClearContents
wssl.Activate
Dim table As Range
Set table = Worksheets("saleslines").Range("a2:k" & lastrow)
For Each row In table.Rows
item = row.Cells(1, 2).Value
name = row.Cells(1, 3).Value
desc = row.Cells(1, 4).Value
hs = row.Cells(1, 5).Value
pack = row.Cells(1, 6).Value
qty = row.Cells(1, 7).Value
unit = row.Cells(1, 8).Value
unpr = row.Cells(1, 9).Value
pric = row.Cells(1, 11).Value
wsso.Activate
lastrow = Worksheets("SO").Cells(Rows.Count, "b").End(xlUp).row
Worksheets("SO").Cells(lastrow + 1, 1).Value = item
Worksheets("SO").Cells(lastrow + 1, 10).Value = hs
Worksheets("SO").Cells(lastrow + 1, 13).Value = qty
Worksheets("SO").Cells(lastrow + 1, 15).Value = unit
Worksheets("SO").Cells(lastrow + 1, 18).Value = unpr
Worksheets("SO").Cells(lastrow + 1, 21).Value = pric
Worksheets("SO").Cells(lastrow + 1, 2).Value = name
Worksheets("SO").Cells(lastrow + 2, 2).Value = desc ' below name
Worksheets("SO").Cells(lastrow + 3, 2).Value = pack ' below description
Next row
End Sub
any help appreciated!