VBA Code to extract number and paste

Wafee

Board Regular
Joined
May 27, 2020
Messages
104
Office Version
  1. 2013
Platform
  1. Windows
Hi,
I am trying to paste data from A,B columns from sheet1 to Aand B sheet2. For the A column , while pasting data I want to paste only numbers from each cells of sheet1. And for B column while pasting i want to remove first 10 letters from left and the paste it. Can someone help me with a code which works faster and dynamic as I am dealing with large amounts of data. Thanks in advance.
 

Excel Facts

Add Bullets to Range
Select range. Press Ctrl+1. On Number tab, choose Custom. Type Alt+7 then space then @ sign (using 7 on numeric keypad)
How about
VBA Code:
Sub Wafee()
   Dim Ary As Variant
   Dim i As Long
   With Sheets("Sheet1")
      Ary = Range("A1:B" & .Range("A" & Rows.Count).End(xlUp)).Value2
   End With
   For i = 1 To UBound(Ary)
      If Not IsNumeric(Ary(i, 1)) Then Ary(i, 1) = ""
      Ary(i, 2) = Mid(Ary(i, 2), 11)
   Next i
   Sheets("Sheet2").Range("A1").Resize(UBound(Ary), 2).Value = Ary
End Sub
 
Upvote 0
How about
VBA Code:
Sub Wafee()
   Dim Ary As Variant
   Dim i As Long
   With Sheets("Sheet1")
      Ary = Range("A1:B" & .Range("A" & Rows.Count).End(xlUp)).Value2
   End With
   For i = 1 To UBound(Ary)
      If Not IsNumeric(Ary(i, 1)) Then Ary(i, 1) = ""
      Ary(i, 2) = Mid(Ary(i, 2), 11)
   Next i
   Sheets("Sheet2").Range("A1").Resize(UBound(Ary), 2).Value = Ary
End Sub
Hey Fluff.
Hope you are doing good. I tried but getting an error at
Ary = Range("A1:B" & .Range("A" & Rows.Count).End(xlUp)).Value2
Error- Method 'Range' of object '_Global' failed.
Thank you in advance.
 
Upvote 0
Oops, it should be
VBA Code:
Ary = Range("A1:B" & .Range("A" & Rows.Count).End(xlUp).Row).Value2
 
Upvote 0
Oops, it should be
VBA Code:
Ary = Range("A1:B" & .Range("A" & Rows.Count).End(xlUp).Row).Value2

Hey Fulff,

For "A" column what I meant was to extract number from the string which will have both text and numbers. The format will have number followed by text (eg : 12-Matt).
 
Upvote 0
In that case can you please post some sample data using the XL2BB add-in.
 
Upvote 0
Hi Fluff,

Below will be the format. Numbers ranges from 1 to 12 not more than that. String initially starts with a number and the a "-" and the the text. First Column will be source and second one has the required out put.
I also has small addition to the requirement. In C column of sheet2 I need their categories based on numbers which is 1-4 should be under cateogory "A", 5-8 should be under "B", 9-12 Should be under "C"


Column A(Sheet1)Column A(Sheet2)Column C(Sheet2)
7 - Jack7B
4 - Raj4A
12 - Mike12C
11 - Susan11C
 
Upvote 0
Please post as sample of your data using the XL2BB add-in, not some fictitious pseudo data pasted to the board.
 
Upvote 0
Please post as sample of your data using the XL2BB add-in, not some fictitious pseudo data pasted to the board.
Hi Fluff, Sorry but I am not able to install XL2BB on my device for some reasons I don't know.
 
Upvote 0
Ok, but I still need a sample of your actual data.
 
Upvote 0

Forum statistics

Threads
1,215,750
Messages
6,126,663
Members
449,326
Latest member
asp123

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