moving content if any, from one sheet to another, in specific cells

Barsoe

New Member
Joined
Mar 12, 2022
Messages
11
Office Version
  1. 365
Platform
  1. Windows
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
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!
 

Excel Facts

How to fill five years of quarters?
Type 1Q-2023 in a cell. Grab the fill handle and drag down or right. After 4Q-2023, Excel will jump to 1Q-2024. Dash can be any character.
It would be easier to help if you could use the XL2BB add-in (icon in the menu) to attach screenshots (not pictures) of your two sheets. Alternately, you could upload a copy of your file to a free site such as www.box.com or www.dropbox.com. Once you do that, mark it for 'Sharing' and you will be given a link to the file that you can post here. Explain in detail what you want to do referring to specific cells, rows, columns and sheets using a few examples from your data (de-sensitized if necessary).
 
Upvote 0

Forum statistics

Threads
1,214,833
Messages
6,121,868
Members
449,054
Latest member
juliecooper255

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top