Left function to paste

excel01noob

Board Regular
Joined
Aug 5, 2019
Messages
93
Office Version
  1. 365
  2. 2016
Have a column with dates in the format "general" including the time (column G)
2021-03-01T00:00:00.000000

I need to take only the date in the format DDMMYYYY which I am trying to insert in column Q all the way down until the last row
What is missing in the below code?

Sub lefties()


Dim LastRow As Long
Dim LResult As String

LastRow = Cells(Rows.Count, "G").End(xlUp).Row

LResult = Left(Range("G2:G" & LastRow), 10)

Range("Q2:Q" & LastRow).Value = LResult

End Sub
 

Excel Facts

How to show all formulas in Excel?
Press Ctrl+` to show all formulas. Press it again to toggle back to numbers. The grave accent is often under the tilde on US keyboards.
VBA Code:
Sub lefties()


Dim LastRow As Long
Dim LResult As String

LastRow = Cells(Rows.Count, "G").End(xlUp).Row

for r = 2 to LastRow
LResult = Left(Range("G" & r), 10)

Range("Q" & r).Value = LResult
next r

End Sub
 
Upvote 0
Another option
VBA Code:
Sub excel01noob()
   With Range("G2", Range("G" & Rows.Count).End(xlUp))
      .Offset(, 10).Value = Evaluate("if({1},left(" & .Address & ",10))")
   End With
End Sub
 
Upvote 0
Glad we could help & thanks for the feedback.
 
Upvote 0

Forum statistics

Threads
1,214,968
Messages
6,122,506
Members
449,089
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