How to set the column where I want to start pasting information

brunoricardo

New Member
Joined
Aug 1, 2013
Messages
20
Hello everyone,

The code below aims to copy several sets of columns and past them into another sheet. How can i say that I just want to start the information to be pasted on the column "F"? I think is something to be with the definition of my dimension "s"...

thanks in advance!!

Sub Copy_Over2()
Application.ScreenUpdating = False
Dim i As Integer
Dim b As Integer
Dim s As Integer


Dim Lastrow As Long
Dim Lastrow2 As Long


Sheets("Sheet1").Activate
For i = 3 To 6
s = s + 1
Lastrow = Cells(Rows.Count, i).End(xlUp).Row + 1
Lastrow2 = Sheets("Sheet2").Cells(Rows.Count, s).End(xlUp).Row + 1
For b = 2 To Lastrow
Sheets("Sheet2").Cells(Lastrow2, s).Value = Cells(b, i).Value
Lastrow2 = Lastrow2 + 1
Next
Next
Application.ScreenUpdating = True
End Sub
 

Excel Facts

Wildcard in VLOOKUP
Use =VLOOKUP("Apple*" to find apple, Apple, or applesauce
You can set s = 5 before your loop.

Or set s = 6 before your loop, but move the s = s +1 to the end of the loop, since it's generally better to increment your variable after you've used it, not before. It's more straightforward that way.

HTH,
 
Upvote 0
Set s to 5 (Column E) before For i = 3 To 6.

Hello! thank you for your help! I already inserted, as you can see below, but there is an error happening. there´s something wrong with syntax used?


Sub Copy_Over2()
Application.ScreenUpdating = False
Dim i As Integer
Dim b As Integer
Dim s As Integer


Dim Lastrow As Long
Dim Lastrow2 As Long


Sheets("Sheet1").Activate

Set s to 5

For i = 3 To 6

s = s + 1
Lastrow = Cells(Rows.Count, i).End(xlUp).Row + 1
Lastrow2 = Sheets("Sheet2").Cells(Rows.Count, s).End(xlUp).Row + 1
For b = 2 To Lastrow
Sheets("Sheet2").Cells(Lastrow2, s).Value = Cells(b, i).Value
Lastrow2 = Lastrow2 + 1
Next
Next
Application.ScreenUpdating = True
End Sub
 
Upvote 0

Forum statistics

Threads
1,223,250
Messages
6,171,036
Members
452,374
Latest member
keccles

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