Help applying Macro to the whole Column

Alvaroro84

Board Regular
Joined
May 13, 2022
Messages
65
Office Version
  1. 2016
Platform
  1. Windows
Instead of applying it into on cell what can i change to apply it to the whole column?

VBA Code:
Sub Return_nth_character()
'declare variables
Dim ws As Worksheet
Set ws = Worksheets("sheet4")
'extract the 3rd character from a string
ws.Range("b1").EntireRow.Select = Mid(ws.Range("A1"), 3, 16)

End Sub
 
Last edited by a moderator:

Excel Facts

Who is Mr Spreadsheet?
Author John Walkenbach was Mr Spreadsheet until his retirement in June 2019.
Your code returns an error for me (you do not use a "Select" command in a line of code where you are setting a value equal to something).

Is this what you are looking for?
VBA Code:
Sub Return_nth_character()
'declare variables
Dim ws As Worksheet
Set ws = Worksheets("sheet4")
Dim lr As Long

'find last row in column A with data
lr = ws.Cells(Rows.Count, "A").End(xlUp).Row

'extract the 3rd character from a string
ws.Range("B1:B" & lr).Formula = "=Mid(A1, 3, 16)"
ws.Range("B1:B" & lr).Value = ws.Range("B1:B" & lr).Value

End Sub
 
Upvote 0
Solution
I accidently added ".EntireRow.Select" to see if it would do the whole row and that's why it ran an error. However, what you provided is exactly what I was looking for Thank you!
 
Upvote 0

Forum statistics

Threads
1,223,893
Messages
6,175,242
Members
452,623
Latest member
russelllowellpercy

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