Code doing different things on different computers

dpaton05

Well-known Member
Joined
Aug 14, 2018
Messages
2,392
Office Version
  1. 365
  2. 2016
Platform
  1. Windows
I don't know how to write VBA code very well so someone has been helping me with this code. The code is meant to copy the rows from the table in the quoting tool to the table in the costing tool. Here are some specifics

Quoting tool
Table Name: npss_quote
Sheet name: NPSS_quote_sheet

Costing tool
File name: costing tool.xlsm
Table name: tblCosting
Sheet name: Home

Once quotes are entered in npss_quote, they need to be copied to the table in the costing tool. Above the quoting tool are several fields that relate to each line in npss_quote. When they are copied to the costing tool, these fields need to be the same for every line in npss_quote to be copied.

The 3 cells at the top of the quoting spreadsheet that are to be copied for every row are:

  • Caseworker in B6
  • Organisation in B7
  • Child/YP in in a merged cell G6:H6


These need to be copied for each row that is copied from npss_quote to tblCosting. The cells in tblCosting that they need to go in are:

  • Caseworker needs to be put in column G
  • Organisation needs to be put in column F
  • Child/YP needs to be put in column D


The location of information that is specific to every row, Date, Service and Price is as follows:

  • Date is column A of npss_quote and needs to go in column A in tblCosting
  • Service is in column B of npss_quote and needs to go in column E in tblCosting
  • Price is in column H of npss_quote and needs to go in column H in tblCosting



The problem here is what the rows looked like in the quoting tool that are to be transferred https://www.screencast.com/t/xYFyzooN and on my computer the result looks like this https://www.screencast.com/t/D1upXJxNP9. On the computer of the person helping me, it looks like this https://app.box.com/s/rnktjirgkxeuc33sdfwpru7pcc40ir1k. This is all with the same code.

The code that I am using for the transfer is

Code:
Private Sub CmdSend_Click()
    Application.ScreenUpdating = False
    Application.EnableEvents = False
    
    Dim desWS As Worksheet
    Dim srcWS As Worksheet
    Set srcWS = ThisWorkbook.Sheets("NPSS_quote_sheet")
    Set desWS = Workbooks("Costing tool.xlsm").Sheets("Home")
    
    Dim lastRow1 As Long
    Dim lastRow2 As Long
    Dim i As Long
    Dim header As Range
    Dim x As Long
    lastRow1 = srcWS.Range("B" & srcWS.Rows.Count).End(xlUp).Row
    lastRow2 = desWS.Cells.Find("*", SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row
    
    With srcWS.Range("A:A,B:B,H:H")
        For i = 1 To .Areas.Count
            x = .Areas(i).Column
            Set header = desWS.Rows(4).Find(.Areas(i).Cells(10), LookIn:=xlValues, lookat:=xlWhole)
            If Not header Is Nothing Then
                srcWS.Range(srcWS.Cells(11, x), srcWS.Cells(lastRow1, x)).Copy
                desWS.Cells(lastRow2 + 1, header.Column).End(xlUp).Offset(1, 0).PasteSpecial xlPasteValues
            End If
        Next i
    End With
    
    With desWS
        .Range("D" & lastRow2 + 1 & ":D" & .Range("A" & .Rows.Count).End(xlUp).Row) = srcWS.Range("G7")
        .Range("F" & lastRow2 + 1 & ":F" & .Range("A" & .Rows.Count).End(xlUp).Row) = srcWS.Range("B7")
        .Range("G" & lastRow2 + 1 & ":G" & .Range("A" & .Rows.Count).End(xlUp).Row) = srcWS.Range("B6")
    End With
    Windows("Costing tool.xlsm").Activate
    ActiveWorkbook.Worksheets("Home").Range("tblCosting[[#Headers],[Date]]").Select
    ActiveWorkbook.Worksheets("Home").ListObjects("tblCosting").Sort.SortFields. _
        Clear
    ActiveWorkbook.Worksheets("Home").ListObjects("tblCosting").Sort.SortFields. _
        Add Key:=ActiveWorkbook.Worksheets("Home").Range("tblCosting[Date]"), SortOn:=xlSortOnValues, Order:= _
        xlAscending, DataOption:=xlSortNormal
    With ActiveWorkbook.Worksheets("Home").ListObjects("tblCosting").Sort
        .header = xlYes
        .MatchCase = False
        .Orientation = xlTopToBottom
        .SortMethod = xlPinYin
        .Apply
    End With
    With Application
        .CutCopyMode = False
        .EnableEvents = True
        .ScreenUpdating = True
    End With
End Sub

Could someone help me with why this won't work please as I am out of ideas?

Thanks,
Dave




 
Last edited:

Excel Facts

Can you AutoAverage in Excel?
There is a drop-down next to the AutoSum symbol. Open the drop-down to choose AVERAGE, COUNT, MAX, or MIN

Forum statistics

Threads
1,224,823
Messages
6,181,177
Members
453,021
Latest member
Justyna P

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