VBA Code check

Isabella

Well-known Member
Joined
Nov 7, 2008
Messages
643
Hi, the below code copies data from from sheet("Raw") to Sheet("Final"), is this the correct method in copying or is there a better solution.

Also i want to add this

.NumberFormat = "#,##0.00_);[Red](#,##0.00)"

to DestAmount, how can i do that?

.Range(AmountRng & lstRow).Copy Destination:=Sheets(ShtFinal).Range(DestAmount)


Code:
Sub Test()

Const ShtRaw = "Raw"
Const ShtFinal = "Final"
Const AmountRng = "G6:G"
Const CCYRng = "H6:H"
Const DateRng = "E6:E"
Const AccountRng = "C6:C"
Const TypeRng = "F6:F"
Const SourceRng = "J6:J"
Const DestAmount = "A2"
Const DestCCY = "B2"
Const DestDate = "C2"
Const DestAccount = "D2"
Const DestType = "E2"
Const DestSource = "F2"

Dim lstRow As Long
    With Sheets(ShtRaw)
        lstRow = .Range("A" & Rows.Count).End(xlUp).Row
        
        .Range(AmountRng & lstRow).Copy Destination:=Sheets(ShtFinal).Range(DestAmount)
        .Range(CCYRng & lstRow).Copy Destination:=Sheets(ShtFinal).Range(DestCCY)
        .Range(DateRng & lstRow).Copy Destination:=Sheets(ShtFinal).Range(DestDate)
        .Range(AccountRng & lstRow).Copy Destination:=Sheets(ShtFinal).Range(DestAccount)
        .Range(TypeRng & lstRow).Copy Destination:=Sheets(ShtFinal).Range(DestType)
        .Range(SourceRng & lstRow).Copy Destination:=Sheets(ShtFinal).Range(DestSource)
    End With
End Sub
 

Excel Facts

Who is Mr Spreadsheet?
Author John Walkenbach was Mr Spreadsheet until his retirement in June 2019.
Code:
    Dim lstRow As Long
    Dim wsFin As Worksheet
    
    Set wsFin = Sheets("Final")
    
    With Sheets("Raw")
        lstRow = .Range("A" & Rows.Count).End(xlUp).Row
        .Range("G6:H" & lstRow).Copy Destination:=wsFin.Range("A2")
        .Range("E6:E" & lstRow).Copy Destination:=wsFin.Range("C2")
        .Range("C6:C" & lstRow).Copy Destination:=wsFin.Range("D2")
        .Range("F6:F" & lstRow).Copy Destination:=wsFin.Range("E2")
        .Range("J6:J" & lstRow).Copy Destination:=wsFin.Range("F2")
    End With
    
    With wsFin
    .Range("A2", .Range("A" & Rows.Count).End(xlUp)).NumberFormat = "#,##0.00_);[Red](#,##0.00)"
    End With
 
Upvote 0

Forum statistics

Threads
1,224,564
Messages
6,179,543
Members
452,924
Latest member
JackiG

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