VBA Help for Copy Left String from Sheet1 Paste in Sheet2

garciausmc

New Member
Joined
Nov 20, 2013
Messages
12
Hello. Requesting some VBA help here. I have data in one range in Sheet1 (say Range Q10:Q1000). I would like to copy only 6 digits from the string and paste it into a different range in Sheet2. Would be great if you could also help with only copying data if the cell is not blank. I understand I can use the Left function but I want to simplify it with a macro. Example string I am trying to extract the left 6 characters from: M2141032040001

I only want "M21410" to be copied from Sheet1 and Pasted into Sheet2.

Thanks!
 

Excel Facts

How can you turn a range sideways?
Copy the range. Select a blank cell. Right-click, Paste Special, then choose Transpose.
Maybe this way
VBA Code:
Sub MM1()
Dim r As Long, x As Long
x = 1
    For r = 10 To 1000
        Sheets("Sheet2").Range("A" & x) = Left(Range("Q" & r), 6)
        x = x + 1
    Next r
End Sub
 
Upvote 0
Solution
Maybe this way
VBA Code:
Sub MM1()
Dim r As Long, x As Long
x = 1
    For r = 10 To 1000
        Sheets("Sheet2").Range("A" & x) = Left(Range("Q" & r), 6)
        x = x + 1
    Next r
End Sub
Almost perfect but I have row headers in Sheet2. I would like it to paste start on the second row (e.g. B2). How can I modify your code to do this?
 
Upvote 0

Forum statistics

Threads
1,215,055
Messages
6,122,902
Members
449,097
Latest member
dbomb1414

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