Selecting Cells for cut, copy, paste using using variables

Steve001

Board Regular
Joined
Apr 13, 2017
Messages
78
Office Version
  1. 365
  2. 2021
  3. 2013
Platform
  1. Windows
Hello All,

A similar question, to my previous post

Lots of information as this seams to be a popular question but i am unable to get them to work
I am trying to select a range of cells and cut, paste them to a different part of my sheet

Example

select row start to row stop by 3 columns wide

paste this to say S1

hope this makes sense

I am using office 363 & office 2021

Regards
 

Excel Facts

What did Pito Salas invent?
Pito Salas, working for Lotus, popularized what would become to be pivot tables. It was released as Lotus Improv in 1989.
Try the following example:

Before the macro:
DANTE AMOR
ABCDEFGHIJK
1ABCDEF
2A2B2C2D2E2F2
3A3B3C3D3E3F3
4A4B4C4D4E4F4
5A5B5C5D5E5F5
6A6B6C6D6E6F6
7A7B7C7D7E7F7
8A8B8C8D8E8F8
9A9B9C9D9E9F9
10A10B10C10D10E10F10
11A11B11C11D11E11F11
12A12B12C12D12E12F12
Hoja1


After the macro:
DANTE AMOR
ABCDEFGHIJK
1ABCDEFB5C5D5
2A2B2C2D2E2F2B6C6D6
3A3B3C3D3E3F3B7C7D7
4A4B4C4D4E4F4B8C8D8
5A5E5F5B9C9D9
6A6E6F6B10C10D10
7A7E7F7
8A8E8F8
9A9E9F9
10A10E10F10
11A11B11C11D11E11F11
12A12B12C12D12E12F12
Hoja1


VBA Code:
Sub cutcopypaste()
  Dim startCol As Long
  Dim startRow As Long
  Dim stopRow As Long
  Dim colWide As Long
 
  startCol = 2      'for example, column B
  startRow = 5
  stopRow = 10
  colWide = 3
 
  Range(Cells(startRow, startCol), Cells(stopRow, startCol + colWide - 1)).Cut Range("H1")
End Sub
 
Upvote 0
Hi Dante,

that works thank you, a question if you can help me

.cut Range ("H1")

what do i need to put so i can use variables to position it

Regards

Steve
 
Upvote 0
what do i need to put so i can use variables to position it

Try this:
VBA Code:
Sub cutcopypaste()
  Dim startCol As Long
  Dim startRow As Long
  Dim stopRow As Long
  Dim colWide As Long
  
  Dim destinationRow As Long
  Dim destinationCol As Long
  
  startCol = 2      'for example, column B
  startRow = 5
  stopRow = 10
  colWide = 3
  
  destinationRow = 1
  destinationCol = 8
  
  Range(Cells(startRow, startCol), Cells(stopRow, startCol + colWide - 1)).Cut Cells(destinationRow, destinationCol)
End Sub

🤗
 
Upvote 0
Solution

Forum statistics

Threads
1,225,741
Messages
6,186,763
Members
453,370
Latest member
juliewar

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