Cut single sell paste to a range with VBA

Dokat

Active Member
Joined
Jan 19, 2015
Messages
304
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
 
That code works for me.
Are you sure that there is data in W22 & AAB22 on the WBC sheet?
 
Upvote 0

Excel Facts

Why does 9 mean SUM in SUBTOTAL?
It is because Sum is the 9th alphabetically in Average, Count, CountA, Max, Min, Product, StDev.S, StDev.P, Sum, VAR.S, VAR.P.
Glad to help & thanks for the feedback.
 
Upvote 0
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")]


 
Upvote 0
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
 
Upvote 0

Forum statistics

Threads
1,214,972
Messages
6,122,530
Members
449,088
Latest member
RandomExceller01

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