problem with selecting a range

kbishop94

Active Member
Joined
Dec 5, 2016
Messages
458
Office Version
  1. 365
Platform
  1. Windows
  2. MacOS
This is on a worksheet. I am using a command button to select (I'm trying to select!) a range on another worksheet and paste it onto the worksheet where the command button is.

THIS works:

Code:
ActiveWorkbook.Worksheets("Seatex Incident Log").Cells(18, 6).Select
Selection.Copy

THESE do NOT:

Code:
ActiveWorkbook.Worksheets("Seatex Incident Log").Cells(18, 18), Cells(707, 18).Select
Selection.Copy
Code:
ActiveWorkbook.Worksheets("Seatex Incident Log").Range(Cells(18, 18), Cells(rCol, 18)).Select
the code works for selecting and copying a single cell, but not for a range.
 
If you only want values try
VBA Code:
Sub kbishop()
   Dim Ary As Variant, Data As Variant
   Dim UsdRws As Long
   
   Ary = Array(1, 4, 5, 6, 10, 17)
   With Sheets("Seatex Incident Log")
      UsdRws = .Range("B" & Rows.Count).End(xlUp).Row
      Data = Application.Index(.Range("B18:R" & UsdRws).Value, Evaluate("row(1:" & UsdRws - 17 & ")"), Ary)
   End With
   ActiveSheet.Range("B2").Resize(UBound(Data), 6).Value = Data
End Sub
 
Upvote 0

Excel Facts

Shade all formula cells
To shade all formula cells: Home, Find & Select, Formulas to select all formulas. Then apply a light fill color.
Try this

VBA Code:
Sub test()
  Dim lr As Long, sh As Worksheet
  Set sh = Sheets("Seatex Incident Log")
  lr = sh.Range("B" & Rows.Count).End(xlUp).Row
  sh.Range("B18:B" & lr & ",E18:G" & lr & ",K18:K" & lr & ",R18:R" & lr).Copy
End Sub
Awesome! thank you ?
 
Upvote 0

Forum statistics

Threads
1,214,591
Messages
6,120,431
Members
448,961
Latest member
nzskater

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