using left function in VBA

ExcelHobbit

New Member
Joined
Jan 8, 2020
Messages
23
Office Version
  1. 2010
Platform
  1. Windows
Hello,

I want to use the left function in VBA, though not in a formula. have the following code, but it isn't working - could be for obvious reasons:

VBA Code:
Range("A2").Select
ActiveCell.Offset(1, 0).Activate

Do Until Cells(ActiveCell.Row, "A").Value = ""
    If Left(Cells(ActiveCell.Row, "A"), 1).Value = "L" Then
    Cells(ActiveCell.Row, "G").FormulaR1C1 = "IFERROR(VLOOKUP(RC4, 'Sheet2'!C1:C4,3,False), """")"
    ActiveCell.Value = ActiveCell.Value
    Else
        If Left(Cells(ActiveCell.Row, "A"), 1).Value = "Q" Then
        Cells(ActiveCell.Row, "G").FormulaR1C1 = "IFERROR(VLOOKUP(RC4, 'Sheet3'!C1:C4,3,False), """")"
        ActiveCell.Value = ActiveCell.Value
        Else
        ActiveCell.Offset(1, 0).Activate
        End If
    End If
Loop

any help would be greatly appreciated.


thanks,
 

Excel Facts

Round to nearest half hour?
Use =MROUND(A2,"0:30") to round to nearest half hour. Use =CEILING(A2,"0:30") to round to next half hour.

mohadin

Well-known Member
Joined
Mar 22, 2015
Messages
1,395
Office Version
  1. 2013
Platform
  1. Windows
Hi
Try
VBA Code:
If Left(Cells(1, "A"), 1) = "Q" Then
 
Solution

ExcelHobbit

New Member
Joined
Jan 8, 2020
Messages
23
Office Version
  1. 2010
Platform
  1. Windows
Awesome, thank you so much. just took out the '.value' works a treat.
 

Lian

New Member
Joined
Jan 26, 2021
Messages
36
Office Version
  1. 365
  2. 2019
  3. 2016
Platform
  1. Windows
ActiveCell.Value = ActiveCell.Value is also wrong or no use
 

ExcelHobbit

New Member
Joined
Jan 8, 2020
Messages
23
Office Version
  1. 2010
Platform
  1. Windows
ActiveCell.Value = ActiveCell.Value is also wrong or no use
if I use range("A2").value = range("A2").value, it copies/pastes as a value. how can I make this work for the activecell?
 

mohadin

Well-known Member
Joined
Mar 22, 2015
Messages
1,395
Office Version
  1. 2013
Platform
  1. Windows
You are welcome
And thank you for the feedback
Be happy & safe
 
Master Excel Bundle

Excel contains over 450 functions, with more added every year. That’s a huge number, so where should you start? Right here with this bundle.

Forum statistics

Threads
1,163,652
Messages
5,832,928
Members
430,175
Latest member
Sheenamarie

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
Top