Cut single sell paste to a range with VBA

Dokat

Active Member
Joined
Jan 19, 2015
Messages
268
Office Version
  1. 365
Hi,


I am trying to rearrange columns and rows in a worksheet. I am using below code to automate the process. It worked seamlessly when I ran the code on same worksheet. However when I cut and paste to another worksheet It doesn't run properly.

It want to cut cell E3 and F3 from Sta Sheet and copy to Worksheet.(Summary").Range B4:B11, and B12:B19. However below code only paste it to B4 and B12. Can anyone help me modify the code so it paste to entire range.

Worksheet Sta is Source Data
Worksheet Summary is where i want to cut and paste the ranges.

Code:
Sub MoveRangeSta()

Dim iCntr
Dim rng As Range
Set rng = Worksheets("Summary").Range("C4:F1111")

For iCntr = rng.Row + rng.Rows.Count - 1 To rng.Row Step -1
If Application.WorksheetFunction.CountA(Rows(iCntr)) = 0 Then Rows(iCntr).EntireRow.Delete
Next

Worksheets("Sta").Range("C4:C12").Cut Destination:=Worksheets("Summary").Range("C4")
Worksheets("Sta").Range("E4:E12").Cut Destination:=Worksheets("Summary").Range("D4")
Worksheets("Sta").Range("C4:C12").Cut Destination:=Worksheets("Summary").Range("C12")
Worksheets("Sta").Range("F4:F12").Cut Destination:=Worksheets("Summary").Range("D12")

Worksheets("Sta").Range("E3").Cut Destination:=Worksheets("Summary").Range("B4:B11")

I posted this on another forum below is the link.




Worksheets("Sta").Range("F3").Cut Destination:=Worksheets("Summary").Range("B12:B19")


End Sub
 

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
74,379
Office Version
  1. 365
Platform
  1. Windows
That code works for me.
Are you sure that there is data in W22 & AAB22 on the WBC sheet?
 

Excel Facts

Can you sort left to right?
To sort left-to-right, use the Sort dialog box. Click Options. Choose "Sort left to right"

Dokat

Active Member
Joined
Jan 19, 2015
Messages
268
Office Version
  1. 365
That code works for me.
Are you sure that there is data in W22 & AAB22 on the WBC sheet?
Now its working, you were right clear function deleted the values AB22 W22 cells. Thanks
 

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
74,379
Office Version
  1. 365
Platform
  1. Windows
Glad to help & thanks for the feedback.
 

Dokat

Active Member
Joined
Jan 19, 2015
Messages
268
Office Version
  1. 365
Glad to help & thanks for the feedback.

Hi Fluff,

How can i combine below two codes into one?
[/Sub MoveRangeWBC()
Worksheets("WBC").Range("E25:E60").Copy Destination:=Worksheets("Summary").Range("C4")
Worksheets("WBC").Range("W25:W60").Copy Destination:=Worksheets("Summary").Range("D4")
Worksheets("WBC").Range("E25:E60").Copy Destination:=Worksheets("Summary").Range("C39")
Worksheets("WBC").Range("AB25:AB60").Copy Destination:=Worksheets("Summary").Range("D39")

Dim iCntr
Dim rng As Range
Set rng = Worksheets("Summary").Range("B4:F1111")

For iCntr = rng.Row + rng.Rows.Count - 1 To rng.Row Step -1

If Application.WorksheetFunction.CountA(Rows(iCntr)) = 0 Then Rows(iCntr).EntireRow.Delete

Next
With Worksheets("WBC")
.Range("W22").Copy Destination:=Worksheets("Summary").Range("B4:B33")
.Range("AB22").Copy Destination:=Worksheets("Summary").Range("B34:B64")


End With
End Sub
]

Combine with below

[/
With Worksheets("WBC")

.Range("W22").Copy Destination:=Worksheets("ST").Range("W22")

.Range("AB22").Copy Destination:=Worksheets("ST").Range("AB22")

.Range("W22").Copy Destination:=Worksheets("WBA").Range("W22")

.Range("AB22").Copy Destination:=Worksheets("WBA").Range("AB22")

.Range("W22").Copy Destination:=Worksheets("WRO").Range("W22")

.Range("AB22").Copy Destination:=Worksheets("WRO").Range("AB22")

.Range("W22").Copy Destination:=Worksheets("WGI").Range("W22")

.Range("AB22").Copy Destination:=Worksheets("WGI").Range("AB22")

.Range("W22").Copy Destination:=Worksheets("WFP").Range("W22")

.Range("AB22").Copy Destination:=Worksheets("WFP").Range("AB22")

.Range("W22").Copy Destination:=Worksheets("WGP").Range("W22")

.Range("AB22").Copy Destination:=Worksheets("WGP").Range("AB22")

.Range("W22").Copy Destination:=Worksheets("WMP").Range("W22")

.Range("AB22").Copy Destination:=Worksheets("WMP").Range("AB22")

.Range("W22").Copy Destination:=Worksheets("MPM").Range("W22")

.Range("AB22").Copy Destination:=Worksheets("MPM").Range("AB22")

.Range("W22").Copy Destination:=Worksheets("MTM").Range("W22")

.Range("AB22").Copy Destination:=Worksheets("MTM").Range("AB22")

.Range("W22").Copy Destination:=Worksheets("MHI").Range("W22")

.Range("AB22").Copy Destination:=Worksheets("MHI").Range("AB22")

.Range("W22").Copy Destination:=Worksheets("MDW").Range("W22")

.Range("AB22").Copy Destination:=Worksheets("MDW").Range("AB22")

.Range("W22").Copy Destination:=Worksheets("CFP").Range("W22")

.Range("AB22").Copy Destination:=Worksheets("CFP").Range("AB22")

.Range("W22").Copy Destination:=Worksheets("CPE").Range("W22")

.Range("AB22").Copy Destination:=Worksheets("CPE").Range("AB22")

.Range("W22").Copy Destination:=Worksheets("CWC").Range("W22")

.Range("AB22").Copy Destination:=Worksheets("CWC").Range("AB22")

.Range("W22").Copy Destination:=Worksheets("RBO").Range("W22")

.Range("AB22").Copy Destination:=Worksheets("RBO").Range("AB22")

.Range("W22").Copy Destination:=Worksheets("RPE").Range("W22")

.Range("AB22").Copy Destination:=Worksheets("RPE").Range("AB22")

.Range("W22").Copy Destination:=Worksheets("RTA").Range("W22")

.Range("AB22").Copy Destination:=Worksheets("RTA").Range("AB22")

.Range("W22").Copy Destination:=Worksheets("OSA").Range("W22")

.Range("AB22").Copy Destination:=Worksheets("OSA").Range("AB22")]


 

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
74,379
Office Version
  1. 365
Platform
  1. Windows
As this is a totally different question, it needs a new thread.
Also in future stop putting your replies inside quotes, as it looks as though you haven't said anything.
And when posting code please use code tags. How to Post Your VBA Code
 
Master Excel Bundle

Excel contains over 450 functions, with more added every year. That’s a huge number, so where should you start? Right here with this bundle.

Forum statistics

Threads
1,167,096
Messages
5,852,153
Members
431,488
Latest member
ePayslip

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
Top