VBA help

Isabella

Well-known Member
Joined
Nov 7, 2008
Messages
643
Hi, the below code opens workbook based on the rngImportPath, how can the code be amended so that copy to shtDst be tailored. So I would like to to copy 3 times

So B2:B copy ShtDst.Range("A6"
D2:D copy......................("B6")
A2:D copy.......................("C6")


With .Range("A2:R" & lstSrcCellRwNum)
.Copy
shtDst.Range("A5").PasteSpecial xlPasteValues
End With



Code:
    strFileName = Range("rngImportPath") & ".xls"

    If Dir(strFileName) = "" Then
            MsgBox prompt:="The File does not exist", _
            Buttons:=vbOKOnly + vbInformation
        Exit Function
      Else
         Set wkbSrc = Workbooks.Open(strFileName)
         Set shtSrc = wkbSrc.Worksheets(1)
         Set wkbThis = ThisWorkbook
         Set shtDst = wkbThis.Sheets(gstrRawHoldings)
    End If
    With shtSrc
         Set lstRowSrc = .Cells(.Rows.Count, "A").End(xlUp)
                 lstSrcCellRwNum = lstRowSrc.Row
               With shtDst
                 On Error Resume Next
                 Intersect(.UsedRange, .Range("A5:R" & Rows.Count)).ClearContents
                 On Error GoTo 0
               End With
             With .Range("A2:R" & lstSrcCellRwNum)
              .Copy
              shtDst.Range("A5").PasteSpecial xlPasteValues
          End With
          Application.DisplayAlerts = False
             ActiveWorkbook.Close
         Application.DisplayAlerts = True
     End With
 

Excel Facts

Spell Check in Excel
Press F7 to start spell check in Excel. Be careful, by default, Excel does not check Capitalized Werds (whoops)
Well, substitute yoir ranges in the piece of code you highighted:
Code:
With .Range("A2:R" & lstSrcCellRwNum)
.Copy
shtDst.Range("A5").PasteSpecial xlPasteValues
End With
so
Code:
With .Range("B2:B" & lstSrcCellRwNum)
.Copy
shtDst.Range("A6").PasteSpecial xlPasteValues
End With
etc
 
Upvote 0

Forum statistics

Threads
1,224,592
Messages
6,179,787
Members
452,942
Latest member
VijayNewtoExcel

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