using left function in VBA

ExcelHobbit

New Member
Joined
Jan 8, 2020
Messages
21
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

Which lookup functions find a value equal or greater than the lookup value?
MATCH uses -1 to find larger value (lookup table must be sorted ZA). XLOOKUP uses 1 to find values greater and does not need to be sorted.

mohadin

Well-known Member
Joined
Mar 22, 2015
Messages
1,091
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
21
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
34
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
21
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,091
Office Version
  1. 2013
Platform
  1. Windows
You are welcome
And thank you for the feedback
Be happy & safe
 

Watch MrExcel Video

Forum statistics

Threads
1,130,425
Messages
5,642,051
Members
417,251
Latest member
Dordrecht

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